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_group.c
1#include "nuklear.h"
2#include "nuklear_internal.h"
3
4/* ===============================================================
5 *
6 * GROUP
7 *
8 * ===============================================================*/
9NK_API nk_bool
11 nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags)
12{
13 struct nk_rect bounds;
14 struct nk_window panel;
15 struct nk_window *win;
16
17 win = ctx->current;
18 nk_panel_alloc_space(&bounds, ctx);
19 {const struct nk_rect *c = &win->layout->clip;
20 if (!NK_INTERSECT(c->x, c->y, c->w, c->h, bounds.x, bounds.y, bounds.w, bounds.h) &&
21 !(flags & NK_WINDOW_MOVABLE)) {
22 return 0;
23 }}
24 if (win->flags & NK_WINDOW_ROM)
25 flags |= NK_WINDOW_ROM;
26
27 /* initialize a fake window to create the panel from */
28 nk_zero(&panel, sizeof(panel));
29 panel.bounds = bounds;
30 panel.flags = flags;
31 panel.scrollbar.x = *x_offset;
32 panel.scrollbar.y = *y_offset;
33 panel.buffer = win->buffer;
34 panel.layout = (struct nk_panel*)nk_create_panel(ctx);
35 ctx->current = &panel;
36 nk_panel_begin(ctx, (flags & NK_WINDOW_TITLE) ? title: 0, NK_PANEL_GROUP);
37
38 win->buffer = panel.buffer;
39 win->buffer.clip = panel.layout->clip;
40 panel.layout->offset_x = x_offset;
41 panel.layout->offset_y = y_offset;
42 panel.layout->parent = win->layout;
43 win->layout = panel.layout;
44
45 ctx->current = win;
46 if ((panel.layout->flags & NK_WINDOW_CLOSED) ||
47 (panel.layout->flags & NK_WINDOW_MINIMIZED))
48 {
49 nk_flags f = panel.layout->flags;
51 if (f & NK_WINDOW_CLOSED)
52 return NK_WINDOW_CLOSED;
53 if (f & NK_WINDOW_MINIMIZED)
55 }
56 return 1;
57}
58NK_API void
60{
61 struct nk_window *win;
62 struct nk_panel *parent;
63 struct nk_panel *g;
64
65 struct nk_rect clip;
66 struct nk_window pan;
67 struct nk_vec2 panel_padding;
68
69 NK_ASSERT(ctx);
70 NK_ASSERT(ctx->current);
71 if (!ctx || !ctx->current)
72 return;
73
74 /* make sure nk_group_begin was called correctly */
75 NK_ASSERT(ctx->current);
76 win = ctx->current;
77 NK_ASSERT(win->layout);
78 g = win->layout;
79 NK_ASSERT(g->parent);
80 parent = g->parent;
81
82 /* dummy window */
83 nk_zero_struct(pan);
84 panel_padding = nk_panel_get_padding(&ctx->style, NK_PANEL_GROUP);
85 pan.bounds.y = g->bounds.y - (g->header_height + g->menu.h);
86 pan.bounds.x = g->bounds.x - panel_padding.x;
87 pan.bounds.w = g->bounds.w + 2 * panel_padding.x;
88 pan.bounds.h = g->bounds.h + g->header_height + g->menu.h;
89 if (g->flags & NK_WINDOW_BORDER) {
90 pan.bounds.x -= g->border;
91 pan.bounds.y -= g->border;
92 pan.bounds.w += 2*g->border;
93 pan.bounds.h += 2*g->border;
94 }
95 if (!(g->flags & NK_WINDOW_NO_SCROLLBAR)) {
96 pan.bounds.w += ctx->style.window.scrollbar_size.x;
97 pan.bounds.h += ctx->style.window.scrollbar_size.y;
98 }
99 pan.scrollbar.x = *g->offset_x;
100 pan.scrollbar.y = *g->offset_y;
101 pan.flags = g->flags;
102 pan.buffer = win->buffer;
103 pan.layout = g;
104 pan.parent = win;
105 ctx->current = &pan;
106
107 /* make sure group has correct clipping rectangle */
108 nk_unify(&clip, &parent->clip, pan.bounds.x, pan.bounds.y,
109 pan.bounds.x + pan.bounds.w, pan.bounds.y + pan.bounds.h + panel_padding.x);
110 nk_push_scissor(&pan.buffer, clip);
111 nk_end(ctx);
112
113 win->buffer = pan.buffer;
114 nk_push_scissor(&win->buffer, parent->clip);
115 ctx->current = win;
116 win->layout = parent;
117 g->bounds = pan.bounds;
118 return;
119}
120NK_API nk_bool
122 struct nk_scroll *scroll, const char *title, nk_flags flags)
123{
124 return nk_group_scrolled_offset_begin(ctx, &scroll->x, &scroll->y, title, flags);
125}
126NK_API nk_bool
127nk_group_begin_titled(struct nk_context *ctx, const char *id,
128 const char *title, nk_flags flags)
129{
130 int id_len;
131 nk_hash id_hash;
132 struct nk_window *win;
133 nk_uint *x_offset;
134 nk_uint *y_offset;
135
136 NK_ASSERT(ctx);
137 NK_ASSERT(id);
138 NK_ASSERT(ctx->current);
139 NK_ASSERT(ctx->current->layout);
140 if (!ctx || !ctx->current || !ctx->current->layout || !id)
141 return 0;
142
143 /* find persistent group scrollbar value */
144 win = ctx->current;
145 id_len = (int)nk_strlen(id);
146 id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
147 x_offset = nk_find_value(win, id_hash);
148 if (!x_offset) {
149 x_offset = nk_add_value(ctx, win, id_hash, 0);
150 y_offset = nk_add_value(ctx, win, id_hash+1, 0);
151
152 NK_ASSERT(x_offset);
153 NK_ASSERT(y_offset);
154 if (!x_offset || !y_offset) return 0;
155 *x_offset = *y_offset = 0;
156 } else if (!(y_offset = nk_find_value(win, id_hash+1))) {
157 y_offset = nk_add_value(ctx, win, id_hash+1, 0);
158 NK_ASSERT(y_offset);
159 if (!y_offset) return 0;
160 *x_offset = *y_offset = 0; /* I think this covers the degenerate case */
161 }
162
163 return nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags);
164}
165NK_API nk_bool
166nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags)
167{
168 return nk_group_begin_titled(ctx, title, title, flags);
169}
170NK_API void
172{
174}
175NK_API void
176nk_group_get_scroll(struct nk_context *ctx, const char *id, nk_uint *x_offset, nk_uint *y_offset)
177{
178 int id_len;
179 nk_hash id_hash;
180 struct nk_window *win;
181 nk_uint *x_offset_ptr;
182 nk_uint *y_offset_ptr;
183
184 NK_ASSERT(ctx);
185 NK_ASSERT(id);
186 NK_ASSERT(ctx->current);
187 NK_ASSERT(ctx->current->layout);
188 if (!ctx || !ctx->current || !ctx->current->layout || !id)
189 return;
190
191 /* find persistent group scrollbar value */
192 win = ctx->current;
193 id_len = (int)nk_strlen(id);
194 id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
195 x_offset_ptr = nk_find_value(win, id_hash);
196 if (!x_offset_ptr) {
197 x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
198 y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
199
200 NK_ASSERT(x_offset_ptr);
201 NK_ASSERT(y_offset_ptr);
202 if (!x_offset_ptr || !y_offset_ptr) return;
203 *x_offset_ptr = *y_offset_ptr = 0;
204 } else if (!(y_offset_ptr = nk_find_value(win, id_hash+1))) {
205 y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
206 NK_ASSERT(y_offset_ptr);
207 if (!y_offset_ptr) return;
208 *x_offset_ptr = *y_offset_ptr = 0;
209 }
210 if (x_offset)
211 *x_offset = *x_offset_ptr;
212 if (y_offset)
213 *y_offset = *y_offset_ptr;
214}
215NK_API void
216nk_group_set_scroll(struct nk_context *ctx, const char *id, nk_uint x_offset, nk_uint y_offset)
217{
218 int id_len;
219 nk_hash id_hash;
220 struct nk_window *win;
221 nk_uint *x_offset_ptr;
222 nk_uint *y_offset_ptr;
223
224 NK_ASSERT(ctx);
225 NK_ASSERT(id);
226 NK_ASSERT(ctx->current);
227 NK_ASSERT(ctx->current->layout);
228 if (!ctx || !ctx->current || !ctx->current->layout || !id)
229 return;
230
231 /* find persistent group scrollbar value */
232 win = ctx->current;
233 id_len = (int)nk_strlen(id);
234 id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
235 x_offset_ptr = nk_find_value(win, id_hash);
236 if (!x_offset_ptr) {
237 x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
238 y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
239
240 NK_ASSERT(x_offset_ptr);
241 NK_ASSERT(y_offset_ptr);
242 if (!x_offset_ptr || !y_offset_ptr) return;
243 *x_offset_ptr = *y_offset_ptr = 0;
244 } else if (!(y_offset_ptr = nk_find_value(win, id_hash+1))) {
245 NK_ASSERT(y_offset_ptr);
246 if (!y_offset_ptr) return;
247 *x_offset_ptr = *y_offset_ptr = 0;
248 }
249 *x_offset_ptr = x_offset;
250 *y_offset_ptr = y_offset;
251}
main API and documentation file
NK_API nk_bool nk_group_begin(struct nk_context *, const char *title, nk_flags)
Starts a new widget group.
@ NK_WINDOW_CLOSED
Directly closes and frees the window at the end of the frame.
Definition nuklear.h:5540
@ NK_WINDOW_MINIMIZED
marks the window as minimized
Definition nuklear.h:5541
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
Definition nuklear.h:5537
NK_API void nk_group_scrolled_end(struct nk_context *)
NK_API void nk_group_get_scroll(struct nk_context *, const char *id, nk_uint *x_offset, nk_uint *y_offset)
NK_API nk_bool nk_group_scrolled_offset_begin(struct nk_context *, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags)
NK_API nk_bool nk_group_begin_titled(struct nk_context *, const char *name, const char *title, nk_flags)
Starts a new widget group.
NK_API void nk_group_set_scroll(struct nk_context *, const char *id, nk_uint x_offset, nk_uint y_offset)
NK_API void nk_end(struct nk_context *ctx)
NK_API void nk_group_end(struct nk_context *)
NK_API nk_bool nk_group_scrolled_begin(struct nk_context *, struct nk_scroll *off, const char *title, nk_flags)