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 y_offset = nk_find_value(win, id_hash+1);
157 return nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags);
158}
159NK_API nk_bool
160nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags)
161{
162 return nk_group_begin_titled(ctx, title, title, flags);
163}
164NK_API void
166{
168}
169NK_API void
170nk_group_get_scroll(struct nk_context *ctx, const char *id, nk_uint *x_offset, nk_uint *y_offset)
171{
172 int id_len;
173 nk_hash id_hash;
174 struct nk_window *win;
175 nk_uint *x_offset_ptr;
176 nk_uint *y_offset_ptr;
177
178 NK_ASSERT(ctx);
179 NK_ASSERT(id);
180 NK_ASSERT(ctx->current);
181 NK_ASSERT(ctx->current->layout);
182 if (!ctx || !ctx->current || !ctx->current->layout || !id)
183 return;
184
185 /* find persistent group scrollbar value */
186 win = ctx->current;
187 id_len = (int)nk_strlen(id);
188 id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
189 x_offset_ptr = nk_find_value(win, id_hash);
190 if (!x_offset_ptr) {
191 x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
192 y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
193
194 NK_ASSERT(x_offset_ptr);
195 NK_ASSERT(y_offset_ptr);
196 if (!x_offset_ptr || !y_offset_ptr) return;
197 *x_offset_ptr = *y_offset_ptr = 0;
198 } else y_offset_ptr = nk_find_value(win, id_hash+1);
199 if (x_offset)
200 *x_offset = *x_offset_ptr;
201 if (y_offset)
202 *y_offset = *y_offset_ptr;
203}
204NK_API void
205nk_group_set_scroll(struct nk_context *ctx, const char *id, nk_uint x_offset, nk_uint y_offset)
206{
207 int id_len;
208 nk_hash id_hash;
209 struct nk_window *win;
210 nk_uint *x_offset_ptr;
211 nk_uint *y_offset_ptr;
212
213 NK_ASSERT(ctx);
214 NK_ASSERT(id);
215 NK_ASSERT(ctx->current);
216 NK_ASSERT(ctx->current->layout);
217 if (!ctx || !ctx->current || !ctx->current->layout || !id)
218 return;
219
220 /* find persistent group scrollbar value */
221 win = ctx->current;
222 id_len = (int)nk_strlen(id);
223 id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP);
224 x_offset_ptr = nk_find_value(win, id_hash);
225 if (!x_offset_ptr) {
226 x_offset_ptr = nk_add_value(ctx, win, id_hash, 0);
227 y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0);
228
229 NK_ASSERT(x_offset_ptr);
230 NK_ASSERT(y_offset_ptr);
231 if (!x_offset_ptr || !y_offset_ptr) return;
232 *x_offset_ptr = *y_offset_ptr = 0;
233 } else y_offset_ptr = nk_find_value(win, id_hash+1);
234 *x_offset_ptr = x_offset;
235 *y_offset_ptr = y_offset;
236}
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:5495
@ NK_WINDOW_MINIMIZED
marks the window as minimized
Definition nuklear.h:5496
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
Definition nuklear.h:5492
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)