2 #include "nuklear_internal.h"
13 elem = nk_create_page_element(ctx);
15 elem->data.win.seq = ctx->seq;
16 return &elem->data.win;
24 nk_free_window(ctx, win->popup.win);
33 nk_remove_table(win, it);
34 nk_free_table(ctx, it);
35 if (it == win->tables)
43 nk_free_page_element(ctx, pe);}
46 nk_find_window(
const struct nk_context *ctx, nk_hash hash,
const char *name)
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))
63 enum nk_window_insert_location loc)
68 if (!win || !ctx)
return;
72 NK_ASSERT(iter != iter->next);
73 NK_ASSERT(iter != win);
74 if (iter == win)
return;
86 if (loc == NK_INSERT_BACK) {
94 ctx->active = ctx->end;
98 ctx->begin->prev = win;
99 win->next = ctx->begin;
109 if (win == ctx->begin || win == ctx->end) {
110 if (win == ctx->begin) {
111 ctx->begin = win->next;
115 if (win == ctx->end) {
116 ctx->end = win->prev;
122 win->next->prev = win->prev;
124 win->prev->next = win->next;
126 if (win == ctx->active || !ctx->active) {
127 ctx->active = ctx->end;
137 struct nk_rect bounds, nk_flags flags)
143 struct nk_rect bounds, nk_flags flags)
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)
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);
166 nk_size name_length = (nk_size)name_len;
167 win = (
struct nk_window*)nk_create_window(ctx);
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);
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;
183 win->widgets_disabled = nk_false;
188 win->flags &= ~(nk_flags)(NK_WINDOW_PRIVATE-1);
190 if (!(win->flags & (NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE)))
191 win->bounds = bounds;
199 NK_ASSERT(win->seq != ctx->seq);
210 }
else nk_start(ctx, win);
215 int inpanel, ishovered;
217 float h = ctx->style.font->
height + 2.0f * style->window.header.padding.y +
218 (2.0f * style->window.header.label_padding.y);
220 win->bounds:
nk_rect(win->bounds.x, win->bounds.y, win->bounds.w, h);
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) {
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) &&
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))
246 if (iter && inpanel && (win != ctx->end)) {
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) &&
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))
264 if (iter && !(win->flags &
NK_WINDOW_ROM) && (win->flags & NK_WINDOW_BACKGROUND)) {
268 if (!(iter->flags & NK_WINDOW_BACKGROUND)) {
271 nk_remove_window(ctx, iter);
272 nk_insert_window(ctx, iter, NK_INSERT_BACK);
275 if (!iter && ctx->end != win) {
276 if (!(win->flags & NK_WINDOW_BACKGROUND)) {
279 nk_remove_window(ctx, win);
280 nk_insert_window(ctx, win, NK_INSERT_BACK);
285 if (ctx->end != win && !(win->flags & NK_WINDOW_BACKGROUND))
289 win->layout = (
struct nk_panel*)nk_create_panel(ctx);
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;
301 NK_ASSERT(ctx->current &&
"if this triggers you forgot to call `nk_begin`");
302 if (!ctx || !ctx->current)
305 layout = ctx->current->layout;
306 if (!layout || (layout->type == NK_PANEL_WINDOW && (ctx->current->flags &
NK_WINDOW_HIDDEN))) {
311 nk_free_panel(ctx, ctx->current->layout);
318 NK_ASSERT(ctx->current);
319 if (!ctx || !ctx->current)
return nk_rect(0,0,0,0);
320 return ctx->current->bounds;
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);
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);
342 NK_ASSERT(ctx->current);
343 if (!ctx || !ctx->current)
return 0;
344 return ctx->current->bounds.w;
350 NK_ASSERT(ctx->current);
351 if (!ctx || !ctx->current)
return 0;
352 return ctx->current->bounds.h;
358 NK_ASSERT(ctx->current);
359 if (!ctx || !ctx->current)
return nk_rect(0,0,0,0);
360 return ctx->current->layout->clip;
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);
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);
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);
394 NK_ASSERT(ctx->current);
395 NK_ASSERT(ctx->current->layout);
396 if (!ctx || !ctx->current)
return 0;
397 return &ctx->current->buffer;
403 NK_ASSERT(ctx->current);
404 if (!ctx || !ctx->current)
return 0;
405 return ctx->current->layout;
412 NK_ASSERT(ctx->current);
413 if (!ctx || !ctx->current)
417 *offset_x = win->scrollbar.x;
419 *offset_y = win->scrollbar.y;
425 NK_ASSERT(ctx->current);
426 NK_ASSERT(ctx->current->layout);
427 if (!ctx || !ctx->current)
return 0;
428 return ctx->current == ctx->active;
434 NK_ASSERT(ctx->current);
438 struct nk_rect actual_bounds = ctx->current->bounds;
440 actual_bounds.h = ctx->current->layout->header_height;
442 return nk_input_is_mouse_hovering_rect(&ctx->input, actual_bounds);
456 if (iter->popup.active && iter->popup.win && nk_input_is_mouse_hovering_rect(&ctx->input, iter->popup.win->bounds))
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))
464 }
else if (nk_input_is_mouse_hovering_rect(&ctx->input, iter->bounds)) {
476 int any_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED);
477 return any_hovered || any_active;
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);
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);
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);
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);
537 return win == ctx->active;
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);
556 NK_ASSERT(ctx->current != win &&
"You cannot close a currently active window");
557 if (ctx->current == win)
return;
563 const char *name,
struct nk_rect bounds)
570 win->bounds = bounds;
574 const char *name,
struct nk_vec2 pos)
578 win->bounds.x = pos.x;
579 win->bounds.y = pos.y;
583 const char *name,
struct nk_vec2 size)
587 win->bounds.w = size.x;
588 win->bounds.h = size.y;
595 NK_ASSERT(ctx->current);
596 if (!ctx || !ctx->current)
599 win->scrollbar.x = offset_x;
600 win->scrollbar.y = offset_y;
604 enum nk_collapse_states c)
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);
616 if (c == NK_MINIMIZED)
622 enum nk_collapse_states c,
int cond)
625 if (!ctx || !cond)
return;
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);
641 if (s == NK_HIDDEN) {
647 enum nk_show_states s,
int cond)
650 if (!ctx || !cond)
return;
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);
679 nk_fill_rect(canvas, space, rounding && space.h > 1.5f ? space.h / 2.0f : 0, color);
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.
@ NK_WINDOW_MINIMIZED
marks the window as minimized
@ NK_WINDOW_HIDDEN
Hides window and stops any window interaction and drawing.
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
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 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 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 struct nk_command_buffer * nk_window_get_canvas(const struct nk_context *ctx)
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 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 struct nk_panel * nk_window_get_panel(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_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_API struct nk_window * nk_window_find(const struct nk_context *ctx, const char *name)
nk_text_width_f width
!< max height of the font
float height
!< user provided font handle