2#include "nuklear_internal.h"
10nk_popup_begin(
struct nk_context *ctx,
enum nk_popup_type type,
11 const char *title, nk_flags flags,
struct nk_rect rect)
23 NK_ASSERT(ctx->current);
24 NK_ASSERT(ctx->current->layout);
25 if (!ctx || !ctx->current || !ctx->current->layout)
30 NK_ASSERT(!((
int)panel->type & (
int)NK_PANEL_SET_POPUP) &&
"popups are not allowed to have popups");
32 title_len = (int)nk_strlen(title);
33 title_hash = nk_murmur_hash(title, (
int)title_len, NK_PANEL_POPUP);
35 popup = win->popup.win;
37 popup = (
struct nk_window*)nk_create_window(ctx);
39 win->popup.win = popup;
40 win->popup.active = 0;
41 win->popup.type = NK_PANEL_POPUP;
45 if (win->popup.name != title_hash) {
46 if (!win->popup.active) {
47 nk_zero(popup,
sizeof(*popup));
48 win->popup.name = title_hash;
49 win->popup.active = 1;
50 win->popup.type = NK_PANEL_POPUP;
56 rect.x += win->layout->clip.x;
57 rect.y += win->layout->clip.y;
62 popup->seq = ctx->seq;
63 popup->layout = (
struct nk_panel*)nk_create_panel(ctx);
65 popup->flags |= NK_WINDOW_BORDER;
66 if (type == NK_POPUP_DYNAMIC)
69 popup->buffer = win->buffer;
70 nk_start_popup(ctx, win);
72 nk_push_scissor(&popup->buffer, nk_null_rect);
74 if (nk_panel_begin(ctx, title, NK_PANEL_POPUP)) {
83 win->popup.active = 1;
84 popup->layout->offset_x = &popup->scrollbar.x;
85 popup->layout->offset_y = &popup->scrollbar.y;
86 popup->layout->parent = win->layout;
96 win->popup.buf.active = 0;
97 win->popup.active = 0;
100 nk_free_panel(ctx, popup->layout);
108 enum nk_panel_type panel_type)
113 int is_active = nk_true;
116 NK_ASSERT(ctx->current);
117 NK_ASSERT(ctx->current->layout);
118 if (!ctx || !ctx->current || !ctx->current->layout)
124 NK_ASSERT(!((
int)panel->type & (
int)NK_PANEL_SET_POPUP));
126 popup = win->popup.win;
129 popup = (
struct nk_window*)nk_create_window(ctx);
131 win->popup.win = popup;
132 win->popup.type = panel_type;
133 nk_command_buffer_init(&popup->buffer, &ctx->memory, NK_CLIPPING_ON);
136 int pressed, in_body, in_header;
137#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
138 pressed = nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT);
140 pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT);
142 in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body);
143 in_header = nk_input_is_mouse_hovering_rect(&ctx->input, header);
144 if (pressed && (!in_body || in_header))
145 is_active = nk_false;
147 win->popup.header = header;
151 struct nk_panel *root = win->layout;
158 popup->bounds = body;
160 popup->layout = (
struct nk_panel*)nk_create_panel(ctx);
161 popup->flags = flags;
162 popup->flags |= NK_WINDOW_BORDER;
164 popup->seq = ctx->seq;
165 win->popup.active = 1;
166 NK_ASSERT(popup->layout);
168 nk_start_popup(ctx, win);
169 popup->buffer = win->buffer;
170 nk_push_scissor(&popup->buffer, nk_null_rect);
171 ctx->current = popup;
173 nk_panel_begin(ctx, 0, panel_type);
174 win->buffer = popup->buffer;
175 popup->layout->parent = win->layout;
176 popup->layout->offset_x = &popup->scrollbar.x;
177 popup->layout->offset_y = &popup->scrollbar.y;
193 if (!ctx || !ctx->current)
return;
195 popup = ctx->current;
196 NK_ASSERT(popup->parent);
197 NK_ASSERT((
int)popup->layout->type & (
int)NK_PANEL_SET_POPUP);
207 NK_ASSERT(ctx->current);
208 NK_ASSERT(ctx->current->layout);
209 if (!ctx || !ctx->current || !ctx->current->layout)
212 popup = ctx->current;
213 if (!popup->parent)
return;
222 win->popup.active = 0;
224 nk_push_scissor(&popup->buffer, nk_null_rect);
227 win->buffer = popup->buffer;
228 nk_finish_popup(ctx, win);
230 nk_push_scissor(&win->buffer, win->layout->clip);
233nk_popup_get_scroll(
const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
238 NK_ASSERT(ctx->current);
239 NK_ASSERT(ctx->current->layout);
240 if (!ctx || !ctx->current || !ctx->current->layout)
243 popup = ctx->current;
245 *offset_x = popup->scrollbar.x;
247 *offset_y = popup->scrollbar.y;
250nk_popup_set_scroll(
struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y)
255 NK_ASSERT(ctx->current);
256 NK_ASSERT(ctx->current->layout);
257 if (!ctx || !ctx->current || !ctx->current->layout)
260 popup = ctx->current;
261 popup->scrollbar.x = offset_x;
262 popup->scrollbar.y = offset_y;
main API and documentation file
@ 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_WINDOW_DYNAMIC
special window type growing up in height while being filled to a certain maximum height
@ NK_WINDOW_REMOVE_ROM
Removes read only mode at the end of the window.
NK_API void nk_end(struct nk_context *ctx)
nk_size allocated
!< growing factor for dynamic memory management