Nuklear
This is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed as a simple embeddable user interface for application and does not have any dependencies, a default render backend or OS window/input handling but instead provides a highly modular, library-based approach, with simple input state for input and draw commands describing primitive shapes as output. So instead of providing a layered library that tries to abstract over a number of platform and render backends, it focuses only on the actual UI.
 
Loading...
Searching...
No Matches
nuklear_window.c
1#include "nuklear.h"
2#include "nuklear_internal.h"
3
4/* ===============================================================
5 *
6 * WINDOW
7 *
8 * ===============================================================*/
9NK_LIB void*
10nk_create_window(struct nk_context *ctx)
11{
12 struct nk_page_element *elem;
13 elem = nk_create_page_element(ctx);
14 if (!elem) return 0;
15 elem->data.win.seq = ctx->seq;
16 return &elem->data.win;
17}
18NK_LIB void
19nk_free_window(struct nk_context *ctx, struct nk_window *win)
20{
21 /* unlink windows from list */
22 struct nk_table *it = win->tables;
23 if (win->popup.win) {
24 nk_free_window(ctx, win->popup.win);
25 win->popup.win = 0;
26 }
27 win->next = 0;
28 win->prev = 0;
29
30 while (it) {
31 /*free window state tables */
32 struct nk_table *n = it->next;
33 nk_remove_table(win, it);
34 nk_free_table(ctx, it);
35 if (it == win->tables)
36 win->tables = n;
37 it = n;
38 }
39
40 /* link windows into freelist */
41 {union nk_page_data *pd = NK_CONTAINER_OF(win, union nk_page_data, win);
42 struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data);
43 nk_free_page_element(ctx, pe);}
44}
45NK_LIB struct nk_window*
46nk_find_window(const struct nk_context *ctx, nk_hash hash, const char *name)
47{
48 struct nk_window *iter;
49 iter = ctx->begin;
50 while (iter) {
51 NK_ASSERT(iter != iter->next);
52 if (iter->name == hash) {
53 int max_len = nk_strlen(iter->name_string);
54 if (!nk_stricmpn(iter->name_string, name, max_len))
55 return iter;
56 }
57 iter = iter->next;
58 }
59 return 0;
60}
61NK_LIB void
62nk_insert_window(struct nk_context *ctx, struct nk_window *win,
63 enum nk_window_insert_location loc)
64{
65 const struct nk_window *iter;
66 NK_ASSERT(ctx);
67 NK_ASSERT(win);
68 if (!win || !ctx) return;
69
70 iter = ctx->begin;
71 while (iter) {
72 NK_ASSERT(iter != iter->next);
73 NK_ASSERT(iter != win);
74 if (iter == win) return;
75 iter = iter->next;
76 }
77
78 if (!ctx->begin) {
79 win->next = 0;
80 win->prev = 0;
81 ctx->begin = win;
82 ctx->end = win;
83 ctx->count = 1;
84 return;
85 }
86 if (loc == NK_INSERT_BACK) {
87 struct nk_window *end;
88 end = ctx->end;
89 end->flags |= NK_WINDOW_ROM;
90 end->next = win;
91 win->prev = ctx->end;
92 win->next = 0;
93 ctx->end = win;
94 ctx->active = ctx->end;
95 ctx->end->flags &= ~(nk_flags)NK_WINDOW_ROM;
96 } else {
97 /*ctx->end->flags |= NK_WINDOW_ROM;*/
98 ctx->begin->prev = win;
99 win->next = ctx->begin;
100 win->prev = 0;
101 ctx->begin = win;
102 ctx->begin->flags &= ~(nk_flags)NK_WINDOW_ROM;
103 }
104 ctx->count++;
105}
106NK_LIB void
107nk_remove_window(struct nk_context *ctx, struct nk_window *win)
108{
109 if (win == ctx->begin || win == ctx->end) {
110 if (win == ctx->begin) {
111 ctx->begin = win->next;
112 if (win->next)
113 win->next->prev = 0;
114 }
115 if (win == ctx->end) {
116 ctx->end = win->prev;
117 if (win->prev)
118 win->prev->next = 0;
119 }
120 } else {
121 if (win->next)
122 win->next->prev = win->prev;
123 if (win->prev)
124 win->prev->next = win->next;
125 }
126 if (win == ctx->active || !ctx->active) {
127 ctx->active = ctx->end;
128 if (ctx->end)
129 ctx->end->flags &= ~(nk_flags)NK_WINDOW_ROM;
130 }
131 win->next = 0;
132 win->prev = 0;
133 ctx->count--;
134}
135NK_API nk_bool
136nk_begin(struct nk_context *ctx, const char *title,
137 struct nk_rect bounds, nk_flags flags)
138{
139 return nk_begin_titled(ctx, title, title, bounds, flags);
140}
141NK_API nk_bool
142nk_begin_titled(struct nk_context *ctx, const char *name, const char *title,
143 struct nk_rect bounds, nk_flags flags)
144{
145 struct nk_window *win;
146 struct nk_style *style;
147 nk_hash name_hash;
148 int name_len;
149 int ret = 0;
150
151 NK_ASSERT(ctx);
152 NK_ASSERT(name);
153 NK_ASSERT(title);
154 NK_ASSERT(ctx->style.font && ctx->style.font->width && "if this triggers you forgot to add a font");
155 NK_ASSERT(!ctx->current && "if this triggers you missed a `nk_end` call");
156 if (!ctx || ctx->current || !title || !name)
157 return 0;
158
159 /* find or create window */
160 style = &ctx->style;
161 name_len = (int)nk_strlen(name);
162 name_hash = nk_murmur_hash(name, (int)name_len, NK_WINDOW_TITLE);
163 win = nk_find_window(ctx, name_hash, name);
164 if (!win) {
165 /* create new window */
166 nk_size name_length = (nk_size)name_len;
167 win = (struct nk_window*)nk_create_window(ctx);
168 NK_ASSERT(win);
169 if (!win) return 0;
170
171 if (flags & NK_WINDOW_BACKGROUND)
172 nk_insert_window(ctx, win, NK_INSERT_FRONT);
173 else nk_insert_window(ctx, win, NK_INSERT_BACK);
174 nk_command_buffer_init(&win->buffer, &ctx->memory, NK_CLIPPING_ON);
175
176 win->flags = flags;
177 win->bounds = bounds;
178 win->name = name_hash;
179 name_length = NK_MIN(name_length, NK_WINDOW_MAX_NAME-1);
180 NK_MEMCPY(win->name_string, name, name_length);
181 win->name_string[name_length] = 0;
182 win->popup.win = 0;
183 win->widgets_disabled = nk_false;
184 if (!ctx->active)
185 ctx->active = win;
186 } else {
187 /* update window */
188 win->flags &= ~(nk_flags)(NK_WINDOW_PRIVATE-1);
189 win->flags |= flags;
190 if (!(win->flags & (NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE)))
191 win->bounds = bounds;
192 /* If this assert triggers you either:
193 *
194 * I.) Have more than one window with the same name or
195 * II.) You forgot to actually draw the window.
196 * More specific you did not call `nk_clear` (nk_clear will be
197 * automatically called for you if you are using one of the
198 * provided demo backends). */
199 NK_ASSERT(win->seq != ctx->seq);
200 win->seq = ctx->seq;
201 if (!ctx->active && !(win->flags & NK_WINDOW_HIDDEN)) {
202 ctx->active = win;
203 ctx->end = win;
204 }
205 }
206 if (win->flags & NK_WINDOW_HIDDEN) {
207 ctx->current = win;
208 win->layout = 0;
209 return 0;
210 } else nk_start(ctx, win);
211
212 /* window overlapping */
213 if (!(win->flags & NK_WINDOW_HIDDEN) && !(win->flags & NK_WINDOW_NO_INPUT))
214 {
215 int inpanel, ishovered;
216 struct nk_window *iter = win;
217 float h = ctx->style.font->height + 2.0f * style->window.header.padding.y +
218 (2.0f * style->window.header.label_padding.y);
219 struct nk_rect win_bounds = (!(win->flags & NK_WINDOW_MINIMIZED))?
220 win->bounds: nk_rect(win->bounds.x, win->bounds.y, win->bounds.w, h);
221
222 /* activate window if hovered and no other window is overlapping this window */
223 inpanel = nk_input_has_mouse_click_down_in_rect(&ctx->input, NK_BUTTON_LEFT, win_bounds, nk_true);
224 inpanel = inpanel && ctx->input.mouse.buttons[NK_BUTTON_LEFT].clicked;
225 ishovered = nk_input_is_mouse_hovering_rect(&ctx->input, win_bounds);
226 if ((win != ctx->active) && ishovered && !ctx->input.mouse.buttons[NK_BUTTON_LEFT].down) {
227 iter = win->next;
228 while (iter) {
229 struct nk_rect iter_bounds = (!(iter->flags & NK_WINDOW_MINIMIZED))?
230 iter->bounds: nk_rect(iter->bounds.x, iter->bounds.y, iter->bounds.w, h);
231 if (NK_INTERSECT(win_bounds.x, win_bounds.y, win_bounds.w, win_bounds.h,
232 iter_bounds.x, iter_bounds.y, iter_bounds.w, iter_bounds.h) &&
233 (!(iter->flags & NK_WINDOW_HIDDEN)))
234 break;
235
236 if (iter->popup.win && iter->popup.active && !(iter->flags & NK_WINDOW_HIDDEN) &&
237 NK_INTERSECT(win->bounds.x, win_bounds.y, win_bounds.w, win_bounds.h,
238 iter->popup.win->bounds.x, iter->popup.win->bounds.y,
239 iter->popup.win->bounds.w, iter->popup.win->bounds.h))
240 break;
241 iter = iter->next;
242 }
243 }
244
245 /* activate window if clicked */
246 if (iter && inpanel && (win != ctx->end)) {
247 iter = win->next;
248 while (iter) {
249 /* try to find a panel with higher priority in the same position */
250 struct nk_rect iter_bounds = (!(iter->flags & NK_WINDOW_MINIMIZED))?
251 iter->bounds: nk_rect(iter->bounds.x, iter->bounds.y, iter->bounds.w, h);
252 if (NK_INBOX(ctx->input.mouse.pos.x, ctx->input.mouse.pos.y,
253 iter_bounds.x, iter_bounds.y, iter_bounds.w, iter_bounds.h) &&
254 !(iter->flags & NK_WINDOW_HIDDEN))
255 break;
256 if (iter->popup.win && iter->popup.active && !(iter->flags & NK_WINDOW_HIDDEN) &&
257 NK_INTERSECT(win_bounds.x, win_bounds.y, win_bounds.w, win_bounds.h,
258 iter->popup.win->bounds.x, iter->popup.win->bounds.y,
259 iter->popup.win->bounds.w, iter->popup.win->bounds.h))
260 break;
261 iter = iter->next;
262 }
263 }
264 if (iter && !(win->flags & NK_WINDOW_ROM) && (win->flags & NK_WINDOW_BACKGROUND)) {
265 win->flags |= (nk_flags)NK_WINDOW_ROM;
266 iter->flags &= ~(nk_flags)NK_WINDOW_ROM;
267 ctx->active = iter;
268 if (!(iter->flags & NK_WINDOW_BACKGROUND)) {
269 /* current window is active in that position so transfer to top
270 * at the highest priority in stack */
271 nk_remove_window(ctx, iter);
272 nk_insert_window(ctx, iter, NK_INSERT_BACK);
273 }
274 } else {
275 if (!iter && ctx->end != win) {
276 if (!(win->flags & NK_WINDOW_BACKGROUND)) {
277 /* current window is active in that position so transfer to top
278 * at the highest priority in stack */
279 nk_remove_window(ctx, win);
280 nk_insert_window(ctx, win, NK_INSERT_BACK);
281 }
282 win->flags &= ~(nk_flags)NK_WINDOW_ROM;
283 ctx->active = win;
284 }
285 if (ctx->end != win && !(win->flags & NK_WINDOW_BACKGROUND))
286 win->flags |= NK_WINDOW_ROM;
287 }
288 }
289 win->layout = (struct nk_panel*)nk_create_panel(ctx);
290 ctx->current = win;
291 ret = nk_panel_begin(ctx, title, NK_PANEL_WINDOW);
292 win->layout->offset_x = &win->scrollbar.x;
293 win->layout->offset_y = &win->scrollbar.y;
294 return ret;
295}
296NK_API void
297nk_end(struct nk_context *ctx)
298{
299 struct nk_panel *layout;
300 NK_ASSERT(ctx);
301 NK_ASSERT(ctx->current && "if this triggers you forgot to call `nk_begin`");
302 if (!ctx || !ctx->current)
303 return;
304
305 layout = ctx->current->layout;
306 if (!layout || (layout->type == NK_PANEL_WINDOW && (ctx->current->flags & NK_WINDOW_HIDDEN))) {
307 ctx->current = 0;
308 return;
309 }
310 nk_panel_end(ctx);
311 nk_free_panel(ctx, ctx->current->layout);
312 ctx->current = 0;
313}
314NK_API struct nk_rect
316{
317 NK_ASSERT(ctx);
318 NK_ASSERT(ctx->current);
319 if (!ctx || !ctx->current) return nk_rect(0,0,0,0);
320 return ctx->current->bounds;
321}
322NK_API struct nk_vec2
324{
325 NK_ASSERT(ctx);
326 NK_ASSERT(ctx->current);
327 if (!ctx || !ctx->current) return nk_vec2(0,0);
328 return nk_vec2(ctx->current->bounds.x, ctx->current->bounds.y);
329}
330NK_API struct nk_vec2
332{
333 NK_ASSERT(ctx);
334 NK_ASSERT(ctx->current);
335 if (!ctx || !ctx->current) return nk_vec2(0,0);
336 return nk_vec2(ctx->current->bounds.w, ctx->current->bounds.h);
337}
338NK_API float
340{
341 NK_ASSERT(ctx);
342 NK_ASSERT(ctx->current);
343 if (!ctx || !ctx->current) return 0;
344 return ctx->current->bounds.w;
345}
346NK_API float
348{
349 NK_ASSERT(ctx);
350 NK_ASSERT(ctx->current);
351 if (!ctx || !ctx->current) return 0;
352 return ctx->current->bounds.h;
353}
354NK_API struct nk_rect
356{
357 NK_ASSERT(ctx);
358 NK_ASSERT(ctx->current);
359 if (!ctx || !ctx->current) return nk_rect(0,0,0,0);
360 return ctx->current->layout->clip;
361}
362NK_API struct nk_vec2
364{
365 NK_ASSERT(ctx);
366 NK_ASSERT(ctx->current);
367 NK_ASSERT(ctx->current->layout);
368 if (!ctx || !ctx->current) return nk_vec2(0,0);
369 return nk_vec2(ctx->current->layout->clip.x, ctx->current->layout->clip.y);
370}
371NK_API struct nk_vec2
373{
374 NK_ASSERT(ctx);
375 NK_ASSERT(ctx->current);
376 NK_ASSERT(ctx->current->layout);
377 if (!ctx || !ctx->current) return nk_vec2(0,0);
378 return nk_vec2(ctx->current->layout->clip.x + ctx->current->layout->clip.w,
379 ctx->current->layout->clip.y + ctx->current->layout->clip.h);
380}
381NK_API struct nk_vec2
383{
384 NK_ASSERT(ctx);
385 NK_ASSERT(ctx->current);
386 NK_ASSERT(ctx->current->layout);
387 if (!ctx || !ctx->current) return nk_vec2(0,0);
388 return nk_vec2(ctx->current->layout->clip.w, ctx->current->layout->clip.h);
389}
390NK_API struct nk_command_buffer*
392{
393 NK_ASSERT(ctx);
394 NK_ASSERT(ctx->current);
395 NK_ASSERT(ctx->current->layout);
396 if (!ctx || !ctx->current) return 0;
397 return &ctx->current->buffer;
398}
399NK_API struct nk_panel*
401{
402 NK_ASSERT(ctx);
403 NK_ASSERT(ctx->current);
404 if (!ctx || !ctx->current) return 0;
405 return ctx->current->layout;
406}
407NK_API void
408nk_window_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
409{
410 struct nk_window *win;
411 NK_ASSERT(ctx);
412 NK_ASSERT(ctx->current);
413 if (!ctx || !ctx->current)
414 return ;
415 win = ctx->current;
416 if (offset_x)
417 *offset_x = win->scrollbar.x;
418 if (offset_y)
419 *offset_y = win->scrollbar.y;
420}
421NK_API nk_bool
423{
424 NK_ASSERT(ctx);
425 NK_ASSERT(ctx->current);
426 NK_ASSERT(ctx->current->layout);
427 if (!ctx || !ctx->current) return 0;
428 return ctx->current == ctx->active;
429}
430NK_API nk_bool
432{
433 NK_ASSERT(ctx);
434 NK_ASSERT(ctx->current);
435 if (!ctx || !ctx->current || (ctx->current->flags & NK_WINDOW_HIDDEN))
436 return 0;
437 else {
438 struct nk_rect actual_bounds = ctx->current->bounds;
439 if (ctx->begin->flags & NK_WINDOW_MINIMIZED) {
440 actual_bounds.h = ctx->current->layout->header_height;
441 }
442 return nk_input_is_mouse_hovering_rect(&ctx->input, actual_bounds);
443 }
444}
445NK_API nk_bool
447{
448 struct nk_window *iter;
449 NK_ASSERT(ctx);
450 if (!ctx) return 0;
451 iter = ctx->begin;
452 while (iter) {
453 /* check if window is being hovered */
454 if(!(iter->flags & NK_WINDOW_HIDDEN)) {
455 /* check if window popup is being hovered */
456 if (iter->popup.active && iter->popup.win && nk_input_is_mouse_hovering_rect(&ctx->input, iter->popup.win->bounds))
457 return 1;
458
459 if (iter->flags & NK_WINDOW_MINIMIZED) {
460 struct nk_rect header = iter->bounds;
461 header.h = ctx->style.font->height + 2 * ctx->style.window.header.padding.y;
462 if (nk_input_is_mouse_hovering_rect(&ctx->input, header))
463 return 1;
464 } else if (nk_input_is_mouse_hovering_rect(&ctx->input, iter->bounds)) {
465 return 1;
466 }
467 }
468 iter = iter->next;
469 }
470 return 0;
471}
472NK_API nk_bool
474{
475 int any_hovered = nk_window_is_any_hovered(ctx);
476 int any_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED);
477 return any_hovered || any_active;
478}
479NK_API nk_bool
480nk_window_is_collapsed(const struct nk_context *ctx, const char *name)
481{
482 int title_len;
483 nk_hash title_hash;
484 struct nk_window *win;
485 NK_ASSERT(ctx);
486 if (!ctx) return 0;
487
488 title_len = (int)nk_strlen(name);
489 title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE);
490 win = nk_find_window(ctx, title_hash, name);
491 if (!win) return 0;
492 return win->flags & NK_WINDOW_MINIMIZED;
493}
494NK_API nk_bool
495nk_window_is_closed(const struct nk_context *ctx, const char *name)
496{
497 int title_len;
498 nk_hash title_hash;
499 struct nk_window *win;
500 NK_ASSERT(ctx);
501 if (!ctx) return 1;
502
503 title_len = (int)nk_strlen(name);
504 title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE);
505 win = nk_find_window(ctx, title_hash, name);
506 if (!win) return 1;
507 return (win->flags & NK_WINDOW_CLOSED);
508}
509NK_API nk_bool
510nk_window_is_hidden(const struct nk_context *ctx, const char *name)
511{
512 int title_len;
513 nk_hash title_hash;
514 struct nk_window *win;
515 NK_ASSERT(ctx);
516 if (!ctx) return 1;
517
518 title_len = (int)nk_strlen(name);
519 title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE);
520 win = nk_find_window(ctx, title_hash, name);
521 if (!win) return 1;
522 return (win->flags & NK_WINDOW_HIDDEN);
523}
524NK_API nk_bool
525nk_window_is_active(const struct nk_context *ctx, const char *name)
526{
527 int title_len;
528 nk_hash title_hash;
529 struct nk_window *win;
530 NK_ASSERT(ctx);
531 if (!ctx) return 0;
532
533 title_len = (int)nk_strlen(name);
534 title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE);
535 win = nk_find_window(ctx, title_hash, name);
536 if (!win) return 0;
537 return win == ctx->active;
538}
539NK_API struct nk_window*
540nk_window_find(const struct nk_context *ctx, const char *name)
541{
542 int title_len;
543 nk_hash title_hash;
544 title_len = (int)nk_strlen(name);
545 title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE);
546 return nk_find_window(ctx, title_hash, name);
547}
548NK_API void
549nk_window_close(struct nk_context *ctx, const char *name)
550{
551 struct nk_window *win;
552 NK_ASSERT(ctx);
553 if (!ctx) return;
554 win = nk_window_find(ctx, name);
555 if (!win) return;
556 NK_ASSERT(ctx->current != win && "You cannot close a currently active window");
557 if (ctx->current == win) return;
558 win->flags |= NK_WINDOW_HIDDEN;
559 win->flags |= NK_WINDOW_CLOSED;
560}
561NK_API void
563 const char *name, struct nk_rect bounds)
564{
565 struct nk_window *win;
566 NK_ASSERT(ctx);
567 if (!ctx) return;
568 win = nk_window_find(ctx, name);
569 if (!win) return;
570 win->bounds = bounds;
571}
572NK_API void
574 const char *name, struct nk_vec2 pos)
575{
576 struct nk_window *win = nk_window_find(ctx, name);
577 if (!win) return;
578 win->bounds.x = pos.x;
579 win->bounds.y = pos.y;
580}
581NK_API void
583 const char *name, struct nk_vec2 size)
584{
585 struct nk_window *win = nk_window_find(ctx, name);
586 if (!win) return;
587 win->bounds.w = size.x;
588 win->bounds.h = size.y;
589}
590NK_API void
591nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y)
592{
593 struct nk_window *win;
594 NK_ASSERT(ctx);
595 NK_ASSERT(ctx->current);
596 if (!ctx || !ctx->current)
597 return;
598 win = ctx->current;
599 win->scrollbar.x = offset_x;
600 win->scrollbar.y = offset_y;
601}
602NK_API void
603nk_window_collapse(struct nk_context *ctx, const char *name,
604 enum nk_collapse_states c)
605{
606 int title_len;
607 nk_hash title_hash;
608 struct nk_window *win;
609 NK_ASSERT(ctx);
610 if (!ctx) return;
611
612 title_len = (int)nk_strlen(name);
613 title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE);
614 win = nk_find_window(ctx, title_hash, name);
615 if (!win) return;
616 if (c == NK_MINIMIZED)
617 win->flags |= NK_WINDOW_MINIMIZED;
618 else win->flags &= ~(nk_flags)NK_WINDOW_MINIMIZED;
619}
620NK_API void
621nk_window_collapse_if(struct nk_context *ctx, const char *name,
622 enum nk_collapse_states c, int cond)
623{
624 NK_ASSERT(ctx);
625 if (!ctx || !cond) return;
626 nk_window_collapse(ctx, name, c);
627}
628NK_API void
629nk_window_show(struct nk_context *ctx, const char *name, enum nk_show_states s)
630{
631 int title_len;
632 nk_hash title_hash;
633 struct nk_window *win;
634 NK_ASSERT(ctx);
635 if (!ctx) return;
636
637 title_len = (int)nk_strlen(name);
638 title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE);
639 win = nk_find_window(ctx, title_hash, name);
640 if (!win) return;
641 if (s == NK_HIDDEN) {
642 win->flags |= NK_WINDOW_HIDDEN;
643 } else win->flags &= ~(nk_flags)NK_WINDOW_HIDDEN;
644}
645NK_API void
646nk_window_show_if(struct nk_context *ctx, const char *name,
647 enum nk_show_states s, int cond)
648{
649 NK_ASSERT(ctx);
650 if (!ctx || !cond) return;
651 nk_window_show(ctx, name, s);
652}
653
654NK_API void
655nk_window_set_focus(struct nk_context *ctx, const char *name)
656{
657 int title_len;
658 nk_hash title_hash;
659 struct nk_window *win;
660 NK_ASSERT(ctx);
661 if (!ctx) return;
662
663 title_len = (int)nk_strlen(name);
664 title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE);
665 win = nk_find_window(ctx, title_hash, name);
666 if (win && ctx->end != win) {
667 nk_remove_window(ctx, win);
668 nk_insert_window(ctx, win, NK_INSERT_BACK);
669 }
670 ctx->active = win;
671}
672NK_API void
673nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding)
674{
675 struct nk_rect space;
676 enum nk_widget_layout_states state = nk_widget(&space, ctx);
677 struct nk_command_buffer *canvas = nk_window_get_canvas(ctx);
678 if (!state) return;
679 nk_fill_rect(canvas, space, rounding && space.h > 1.5f ? space.h / 2.0f : 0, color);
680}
main API and documentation file
NK_API struct nk_vec2 nk_window_get_content_region_max(const struct nk_context *ctx)
NK_API void nk_window_close(struct nk_context *ctx, const char *name)
NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding)
@ NK_WINDOW_CLOSED
Directly closes and frees the window at the end of the frame.
Definition nuklear.h:5495
@ NK_WINDOW_MINIMIZED
marks the window as minimized
Definition nuklear.h:5496
@ NK_WINDOW_HIDDEN
Hides window and stops any window interaction and drawing.
Definition nuklear.h:5494
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
Definition nuklear.h:5492
NK_API nk_bool nk_window_is_hovered(const struct nk_context *ctx)
NK_API void nk_window_collapse_if(struct nk_context *ctx, const char *name, enum nk_collapse_states state, int cond)
NK_API struct nk_command_buffer * nk_window_get_canvas(const struct nk_context *ctx)
NK_API void nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y)
NK_API struct nk_vec2 nk_window_get_size(const struct nk_context *ctx)
NK_API nk_bool nk_window_is_active(const struct nk_context *ctx, const char *name)
NK_API void nk_window_set_focus(struct nk_context *ctx, const char *name)
NK_API nk_bool nk_item_is_any_active(const struct nk_context *ctx)
NK_API nk_bool nk_window_is_any_hovered(const struct nk_context *ctx)
NK_API nk_bool nk_window_is_hidden(const struct nk_context *ctx, const char *name)
NK_API void nk_fill_rect(struct nk_command_buffer *, struct nk_rect, float rounding, struct nk_color)
filled shades
NK_API struct nk_vec2 nk_window_get_content_region_size(const struct nk_context *ctx)
NK_API struct nk_panel * nk_window_get_panel(const struct nk_context *ctx)
NK_API void nk_window_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
NK_API void nk_window_set_position(struct nk_context *ctx, const char *name, struct nk_vec2 pos)
NK_API void nk_window_show(struct nk_context *ctx, const char *name, enum nk_show_states state)
NK_API nk_bool nk_window_is_collapsed(const struct nk_context *ctx, const char *name)
NK_API void nk_window_collapse(struct nk_context *ctx, const char *name, enum nk_collapse_states state)
NK_API nk_bool nk_window_has_focus(const struct nk_context *ctx)
NK_API struct nk_window * nk_window_find(const struct nk_context *ctx, const char *name)
NK_API void nk_window_set_bounds(struct nk_context *ctx, const char *name, struct nk_rect bounds)
NK_API struct nk_rect nk_window_get_bounds(const struct nk_context *ctx)
NK_API void nk_window_show_if(struct nk_context *ctx, const char *name, enum nk_show_states state, int cond)
NK_API float nk_window_get_height(const struct nk_context *ctx)
NK_API nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags)
NK_API nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags)
NK_API void nk_window_set_size(struct nk_context *ctx, const char *name, struct nk_vec2 size)
NK_API struct nk_vec2 nk_window_get_content_region_min(const struct nk_context *ctx)
NK_API float nk_window_get_width(const struct nk_context *ctx)
nk_window_get_width
nk_widget_layout_states
Definition nuklear.h:3081
NK_API struct nk_rect nk_window_get_content_region(const struct nk_context *ctx)
NK_API nk_bool nk_window_is_closed(const struct nk_context *ctx, const char *name)
NK_API void nk_end(struct nk_context *ctx)
NK_API struct nk_vec2 nk_window_get_position(const struct nk_context *ctx)
nk_text_width_f width
!< max height of the font
Definition nuklear.h:4009
float height
!< user provided font handle
Definition nuklear.h:4008