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)
67 popup->flags |= NK_WINDOW_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)) {
79 root->flags |= NK_WINDOW_ROM;
80 root->flags &= ~(nk_flags)NK_WINDOW_REMOVE_ROM;
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;
93 root->flags |= NK_WINDOW_REMOVE_ROM;
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;
153 root->flags |= NK_WINDOW_REMOVE_ROM;
156 win->popup.buf.active = 0;
159 popup->bounds = body;
161 popup->layout = (
struct nk_panel*)nk_create_panel(ctx);
162 popup->flags = flags;
163 popup->flags |= NK_WINDOW_BORDER;
164 popup->flags |= NK_WINDOW_DYNAMIC;
165 popup->seq = ctx->seq;
166 win->popup.active = 1;
167 NK_ASSERT(popup->layout);
169 nk_start_popup(ctx, win);
170 popup->buffer = win->buffer;
171 nk_push_scissor(&popup->buffer, nk_null_rect);
172 ctx->current = popup;
174 nk_panel_begin(ctx, 0, panel_type);
175 win->buffer = popup->buffer;
176 popup->layout->parent = win->layout;
177 popup->layout->offset_x = &popup->scrollbar.x;
178 popup->layout->offset_y = &popup->scrollbar.y;
184 root->flags |= NK_WINDOW_ROM;
194 if (!ctx || !ctx->current)
return;
196 popup = ctx->current;
197 NK_ASSERT(popup->parent);
198 NK_ASSERT((
int)popup->layout->type & (
int)NK_PANEL_SET_POPUP);
199 popup->flags |= NK_WINDOW_HIDDEN;
208 NK_ASSERT(ctx->current);
209 NK_ASSERT(ctx->current->layout);
210 if (!ctx || !ctx->current || !ctx->current->layout)
213 popup = ctx->current;
214 if (!popup->parent)
return;
216 if (popup->flags & NK_WINDOW_HIDDEN) {
220 root->flags |= NK_WINDOW_REMOVE_ROM;
223 win->popup.active = 0;
225 nk_push_scissor(&popup->buffer, nk_null_rect);
228 win->buffer = popup->buffer;
229 nk_finish_popup(ctx, win);
231 nk_push_scissor(&win->buffer, win->layout->clip);
234nk_popup_get_scroll(
const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
239 NK_ASSERT(ctx->current);
240 NK_ASSERT(ctx->current->layout);
241 if (!ctx || !ctx->current || !ctx->current->layout)
244 popup = ctx->current;
246 *offset_x = popup->scrollbar.x;
248 *offset_y = popup->scrollbar.y;
251nk_popup_set_scroll(
struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y)
256 NK_ASSERT(ctx->current);
257 NK_ASSERT(ctx->current->layout);
258 if (!ctx || !ctx->current || !ctx->current->layout)
261 popup = ctx->current;
262 popup->scrollbar.x = offset_x;
263 popup->scrollbar.y = offset_y;
nk_size allocated
!< growing factor for dynamic memory management