1
2 static int
overview(struct nk_context * ctx)3 overview(struct nk_context *ctx)
4 {
5 /* window flags */
6 static int show_menu = nk_true;
7 static int titlebar = nk_true;
8 static int border = nk_true;
9 static int resize = nk_true;
10 static int movable = nk_true;
11 static int no_scrollbar = nk_false;
12 static int scale_left = nk_false;
13 static nk_flags window_flags = 0;
14 static int minimizable = nk_true;
15
16 /* popups */
17 static enum nk_style_header_align header_align = NK_HEADER_RIGHT;
18 static int show_app_about = nk_false;
19
20 /* window flags */
21 window_flags = 0;
22 ctx->style.window.header.align = header_align;
23 if (border) window_flags |= NK_WINDOW_BORDER;
24 if (resize) window_flags |= NK_WINDOW_SCALABLE;
25 if (movable) window_flags |= NK_WINDOW_MOVABLE;
26 if (no_scrollbar) window_flags |= NK_WINDOW_NO_SCROLLBAR;
27 if (scale_left) window_flags |= NK_WINDOW_SCALE_LEFT;
28 if (minimizable) window_flags |= NK_WINDOW_MINIMIZABLE;
29
30 if (nk_begin(ctx, "Overview", nk_rect(10, 10, 400, 600), window_flags))
31 {
32 if (show_menu)
33 {
34 /* menubar */
35 enum menu_states {MENU_DEFAULT, MENU_WINDOWS};
36 static nk_size mprog = 60;
37 static int mslider = 10;
38 static int mcheck = nk_true;
39 nk_menubar_begin(ctx);
40
41 /* menu #1 */
42 nk_layout_row_begin(ctx, NK_STATIC, 25, 5);
43 nk_layout_row_push(ctx, 45);
44 if (nk_menu_begin_label(ctx, "MENU", NK_TEXT_LEFT, nk_vec2(120, 200)))
45 {
46 static size_t prog = 40;
47 static int slider = 10;
48 static int check = nk_true;
49 nk_layout_row_dynamic(ctx, 25, 1);
50 if (nk_menu_item_label(ctx, "Hide", NK_TEXT_LEFT))
51 show_menu = nk_false;
52 if (nk_menu_item_label(ctx, "About", NK_TEXT_LEFT))
53 show_app_about = nk_true;
54 nk_progress(ctx, &prog, 100, NK_MODIFIABLE);
55 nk_slider_int(ctx, 0, &slider, 16, 1);
56 nk_checkbox_label(ctx, "check", &check);
57 nk_menu_end(ctx);
58 }
59 /* menu #2 */
60 nk_layout_row_push(ctx, 60);
61 if (nk_menu_begin_label(ctx, "ADVANCED", NK_TEXT_LEFT, nk_vec2(200, 600)))
62 {
63 enum menu_state {MENU_NONE,MENU_FILE, MENU_EDIT,MENU_VIEW,MENU_CHART};
64 static enum menu_state menu_state = MENU_NONE;
65 enum nk_collapse_states state;
66
67 state = (menu_state == MENU_FILE) ? NK_MAXIMIZED: NK_MINIMIZED;
68 if (nk_tree_state_push(ctx, NK_TREE_TAB, "FILE", &state)) {
69 menu_state = MENU_FILE;
70 nk_menu_item_label(ctx, "New", NK_TEXT_LEFT);
71 nk_menu_item_label(ctx, "Open", NK_TEXT_LEFT);
72 nk_menu_item_label(ctx, "Save", NK_TEXT_LEFT);
73 nk_menu_item_label(ctx, "Close", NK_TEXT_LEFT);
74 nk_menu_item_label(ctx, "Exit", NK_TEXT_LEFT);
75 nk_tree_pop(ctx);
76 } else menu_state = (menu_state == MENU_FILE) ? MENU_NONE: menu_state;
77
78 state = (menu_state == MENU_EDIT) ? NK_MAXIMIZED: NK_MINIMIZED;
79 if (nk_tree_state_push(ctx, NK_TREE_TAB, "EDIT", &state)) {
80 menu_state = MENU_EDIT;
81 nk_menu_item_label(ctx, "Copy", NK_TEXT_LEFT);
82 nk_menu_item_label(ctx, "Delete", NK_TEXT_LEFT);
83 nk_menu_item_label(ctx, "Cut", NK_TEXT_LEFT);
84 nk_menu_item_label(ctx, "Paste", NK_TEXT_LEFT);
85 nk_tree_pop(ctx);
86 } else menu_state = (menu_state == MENU_EDIT) ? MENU_NONE: menu_state;
87
88 state = (menu_state == MENU_VIEW) ? NK_MAXIMIZED: NK_MINIMIZED;
89 if (nk_tree_state_push(ctx, NK_TREE_TAB, "VIEW", &state)) {
90 menu_state = MENU_VIEW;
91 nk_menu_item_label(ctx, "About", NK_TEXT_LEFT);
92 nk_menu_item_label(ctx, "Options", NK_TEXT_LEFT);
93 nk_menu_item_label(ctx, "Customize", NK_TEXT_LEFT);
94 nk_tree_pop(ctx);
95 } else menu_state = (menu_state == MENU_VIEW) ? MENU_NONE: menu_state;
96
97 state = (menu_state == MENU_CHART) ? NK_MAXIMIZED: NK_MINIMIZED;
98 if (nk_tree_state_push(ctx, NK_TREE_TAB, "CHART", &state)) {
99 size_t i = 0;
100 const float values[]={26.0f,13.0f,30.0f,15.0f,25.0f,10.0f,20.0f,40.0f,12.0f,8.0f,22.0f,28.0f};
101 menu_state = MENU_CHART;
102 nk_layout_row_dynamic(ctx, 150, 1);
103 nk_chart_begin(ctx, NK_CHART_COLUMN, NK_LEN(values), 0, 50);
104 for (i = 0; i < NK_LEN(values); ++i)
105 nk_chart_push(ctx, values[i]);
106 nk_chart_end(ctx);
107 nk_tree_pop(ctx);
108 } else menu_state = (menu_state == MENU_CHART) ? MENU_NONE: menu_state;
109 nk_menu_end(ctx);
110 }
111 /* menu widgets */
112 nk_layout_row_push(ctx, 70);
113 nk_progress(ctx, &mprog, 100, NK_MODIFIABLE);
114 nk_slider_int(ctx, 0, &mslider, 16, 1);
115 nk_checkbox_label(ctx, "check", &mcheck);
116 nk_menubar_end(ctx);
117 }
118
119 if (show_app_about)
120 {
121 /* about popup */
122 static struct nk_rect s = {20, 100, 300, 190};
123 if (nk_popup_begin(ctx, NK_POPUP_STATIC, "About", NK_WINDOW_CLOSABLE, s))
124 {
125 nk_layout_row_dynamic(ctx, 20, 1);
126 nk_label(ctx, "Nuklear", NK_TEXT_LEFT);
127 nk_label(ctx, "By Micha Mettke", NK_TEXT_LEFT);
128 nk_label(ctx, "nuklear is licensed under the public domain License.", NK_TEXT_LEFT);
129 nk_popup_end(ctx);
130 } else show_app_about = nk_false;
131 }
132
133 /* window flags */
134 if (nk_tree_push(ctx, NK_TREE_TAB, "Window", NK_MINIMIZED)) {
135 nk_layout_row_dynamic(ctx, 30, 2);
136 nk_checkbox_label(ctx, "Titlebar", &titlebar);
137 nk_checkbox_label(ctx, "Menu", &show_menu);
138 nk_checkbox_label(ctx, "Border", &border);
139 nk_checkbox_label(ctx, "Resizable", &resize);
140 nk_checkbox_label(ctx, "Movable", &movable);
141 nk_checkbox_label(ctx, "No Scrollbar", &no_scrollbar);
142 nk_checkbox_label(ctx, "Minimizable", &minimizable);
143 nk_checkbox_label(ctx, "Scale Left", &scale_left);
144 nk_tree_pop(ctx);
145 }
146
147 if (nk_tree_push(ctx, NK_TREE_TAB, "Widgets", NK_MINIMIZED))
148 {
149 enum options {A,B,C};
150 static int checkbox;
151 static int option;
152 if (nk_tree_push(ctx, NK_TREE_NODE, "Text", NK_MINIMIZED))
153 {
154 /* Text Widgets */
155 nk_layout_row_dynamic(ctx, 20, 1);
156 nk_label(ctx, "Label aligned left", NK_TEXT_LEFT);
157 nk_label(ctx, "Label aligned centered", NK_TEXT_CENTERED);
158 nk_label(ctx, "Label aligned right", NK_TEXT_RIGHT);
159 nk_label_colored(ctx, "Blue text", NK_TEXT_LEFT, nk_rgb(0,0,255));
160 nk_label_colored(ctx, "Yellow text", NK_TEXT_LEFT, nk_rgb(255,255,0));
161 nk_text(ctx, "Text without /0", 15, NK_TEXT_RIGHT);
162
163 nk_layout_row_static(ctx, 100, 200, 1);
164 nk_label_wrap(ctx, "This is a very long line to hopefully get this text to be wrapped into multiple lines to show line wrapping");
165 nk_layout_row_dynamic(ctx, 100, 1);
166 nk_label_wrap(ctx, "This is another long text to show dynamic window changes on multiline text");
167 nk_tree_pop(ctx);
168 }
169
170 if (nk_tree_push(ctx, NK_TREE_NODE, "Button", NK_MINIMIZED))
171 {
172 /* Buttons Widgets */
173 nk_layout_row_static(ctx, 30, 100, 3);
174 if (nk_button_label(ctx, "Button"))
175 fprintf(stdout, "Button pressed!\n");
176 nk_button_set_behavior(ctx, NK_BUTTON_REPEATER);
177 if (nk_button_label(ctx, "Repeater"))
178 fprintf(stdout, "Repeater is being pressed!\n");
179 nk_button_set_behavior(ctx, NK_BUTTON_DEFAULT);
180 nk_button_color(ctx, nk_rgb(0,0,255));
181
182 nk_layout_row_static(ctx, 25, 25, 8);
183 nk_button_symbol(ctx, NK_SYMBOL_CIRCLE_SOLID);
184 nk_button_symbol(ctx, NK_SYMBOL_CIRCLE_OUTLINE);
185 nk_button_symbol(ctx, NK_SYMBOL_RECT_SOLID);
186 nk_button_symbol(ctx, NK_SYMBOL_RECT_OUTLINE);
187 nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_UP);
188 nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_DOWN);
189 nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_LEFT);
190 nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT);
191
192 nk_layout_row_static(ctx, 30, 100, 2);
193 nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_LEFT, "prev", NK_TEXT_RIGHT);
194 nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_RIGHT, "next", NK_TEXT_LEFT);
195 nk_tree_pop(ctx);
196 }
197
198 if (nk_tree_push(ctx, NK_TREE_NODE, "Basic", NK_MINIMIZED))
199 {
200 /* Basic widgets */
201 static int int_slider = 5;
202 static float float_slider = 2.5f;
203 static size_t prog_value = 40;
204 static float property_float = 2;
205 static int property_int = 10;
206 static int property_neg = 10;
207
208 static float range_float_min = 0;
209 static float range_float_max = 100;
210 static float range_float_value = 50;
211 static int range_int_min = 0;
212 static int range_int_value = 2048;
213 static int range_int_max = 4096;
214 static const float ratio[] = {120, 150};
215
216 nk_layout_row_static(ctx, 30, 100, 1);
217 nk_checkbox_label(ctx, "Checkbox", &checkbox);
218
219 nk_layout_row_static(ctx, 30, 80, 3);
220 option = nk_option_label(ctx, "optionA", option == A) ? A : option;
221 option = nk_option_label(ctx, "optionB", option == B) ? B : option;
222 option = nk_option_label(ctx, "optionC", option == C) ? C : option;
223
224
225 nk_layout_row(ctx, NK_STATIC, 30, 2, ratio);
226 nk_labelf(ctx, NK_TEXT_LEFT, "Slider int");
227 nk_slider_int(ctx, 0, &int_slider, 10, 1);
228
229 nk_label(ctx, "Slider float", NK_TEXT_LEFT);
230 nk_slider_float(ctx, 0, &float_slider, 5.0, 0.5f);
231 nk_labelf(ctx, NK_TEXT_LEFT, "Progressbar: %zu" , prog_value);
232 nk_progress(ctx, &prog_value, 100, NK_MODIFIABLE);
233
234 nk_layout_row(ctx, NK_STATIC, 25, 2, ratio);
235 nk_label(ctx, "Property float:", NK_TEXT_LEFT);
236 nk_property_float(ctx, "Float:", 0, &property_float, 64.0f, 0.1f, 0.2f);
237 nk_label(ctx, "Property int:", NK_TEXT_LEFT);
238 nk_property_int(ctx, "Int:", 0, &property_int, 100.0f, 1, 1);
239 nk_label(ctx, "Property neg:", NK_TEXT_LEFT);
240 nk_property_int(ctx, "Neg:", -10, &property_neg, 10, 1, 1);
241
242 nk_layout_row_dynamic(ctx, 25, 1);
243 nk_label(ctx, "Range:", NK_TEXT_LEFT);
244 nk_layout_row_dynamic(ctx, 25, 3);
245 nk_property_float(ctx, "#min:", 0, &range_float_min, range_float_max, 1.0f, 0.2f);
246 nk_property_float(ctx, "#float:", range_float_min, &range_float_value, range_float_max, 1.0f, 0.2f);
247 nk_property_float(ctx, "#max:", range_float_min, &range_float_max, 100, 1.0f, 0.2f);
248
249 nk_property_int(ctx, "#min:", INT_MIN, &range_int_min, range_int_max, 1, 10);
250 nk_property_int(ctx, "#neg:", range_int_min, &range_int_value, range_int_max, 1, 10);
251 nk_property_int(ctx, "#max:", range_int_min, &range_int_max, INT_MAX, 1, 10);
252
253 nk_tree_pop(ctx);
254 }
255
256 if (nk_tree_push(ctx, NK_TREE_NODE, "Selectable", NK_MINIMIZED))
257 {
258 if (nk_tree_push(ctx, NK_TREE_NODE, "List", NK_MINIMIZED))
259 {
260 static int selected[4] = {nk_false, nk_false, nk_true, nk_false};
261 nk_layout_row_static(ctx, 18, 100, 1);
262 nk_selectable_label(ctx, "Selectable", NK_TEXT_LEFT, &selected[0]);
263 nk_selectable_label(ctx, "Selectable", NK_TEXT_LEFT, &selected[1]);
264 nk_label(ctx, "Not Selectable", NK_TEXT_LEFT);
265 nk_selectable_label(ctx, "Selectable", NK_TEXT_LEFT, &selected[2]);
266 nk_selectable_label(ctx, "Selectable", NK_TEXT_LEFT, &selected[3]);
267 nk_tree_pop(ctx);
268 }
269 if (nk_tree_push(ctx, NK_TREE_NODE, "Grid", NK_MINIMIZED))
270 {
271 int i;
272 static int selected[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
273 nk_layout_row_static(ctx, 50, 50, 4);
274 for (i = 0; i < 16; ++i) {
275 if (nk_selectable_label(ctx, "Z", NK_TEXT_CENTERED, &selected[i])) {
276 int x = (i % 4), y = i / 4;
277 if (x > 0) selected[i - 1] ^= 1;
278 if (x < 3) selected[i + 1] ^= 1;
279 if (y > 0) selected[i - 4] ^= 1;
280 if (y < 3) selected[i + 4] ^= 1;
281 }
282 }
283 nk_tree_pop(ctx);
284 }
285 nk_tree_pop(ctx);
286 }
287
288 if (nk_tree_push(ctx, NK_TREE_NODE, "Combo", NK_MINIMIZED))
289 {
290 /* Combobox Widgets
291 * In this library comboboxes are not limited to being a popup
292 * list of selectable text. Instead it is a abstract concept of
293 * having something that is *selected* or displayed, a popup window
294 * which opens if something needs to be modified and the content
295 * of the popup which causes the *selected* or displayed value to
296 * change or if wanted close the combobox.
297 *
298 * While strange at first handling comboboxes in a abstract way
299 * solves the problem of overloaded window content. For example
300 * changing a color value requires 4 value modifier (slider, property,...)
301 * for RGBA then you need a label and ways to display the current color.
302 * If you want to go fancy you even add rgb and hsv ratio boxes.
303 * While fine for one color if you have a lot of them it because
304 * tedious to look at and quite wasteful in space. You could add
305 * a popup which modifies the color but this does not solve the
306 * fact that it still requires a lot of cluttered space to do.
307 *
308 * In these kind of instance abstract comboboxes are quite handy. All
309 * value modifiers are hidden inside the combobox popup and only
310 * the color is shown if not open. This combines the clarity of the
311 * popup with the ease of use of just using the space for modifiers.
312 *
313 * Other instances are for example time and especially date picker,
314 * which only show the currently activated time/data and hide the
315 * selection logic inside the combobox popup.
316 */
317 static float chart_selection = 8.0f;
318 static int current_weapon = 0;
319 static int check_values[5];
320 static float position[3];
321 static struct nk_color combo_color = {130, 50, 50, 255};
322 static struct nk_colorf combo_color2 = {0.509f, 0.705f, 0.2f, 1.0f};
323 static size_t prog_a = 20, prog_b = 40, prog_c = 10, prog_d = 90;
324 static const char *weapons[] = {"Fist","Pistol","Shotgun","Plasma","BFG"};
325
326 char buffer[64];
327 size_t sum = 0;
328
329 /* default combobox */
330 nk_layout_row_static(ctx, 25, 200, 1);
331 current_weapon = nk_combo(ctx, weapons, NK_LEN(weapons), current_weapon, 25, nk_vec2(200,200));
332
333 /* slider color combobox */
334 if (nk_combo_begin_color(ctx, combo_color, nk_vec2(200,200))) {
335 float ratios[] = {0.15f, 0.85f};
336 nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratios);
337 nk_label(ctx, "R:", NK_TEXT_LEFT);
338 combo_color.r = (nk_byte)nk_slide_int(ctx, 0, combo_color.r, 255, 5);
339 nk_label(ctx, "G:", NK_TEXT_LEFT);
340 combo_color.g = (nk_byte)nk_slide_int(ctx, 0, combo_color.g, 255, 5);
341 nk_label(ctx, "B:", NK_TEXT_LEFT);
342 combo_color.b = (nk_byte)nk_slide_int(ctx, 0, combo_color.b, 255, 5);
343 nk_label(ctx, "A:", NK_TEXT_LEFT);
344 combo_color.a = (nk_byte)nk_slide_int(ctx, 0, combo_color.a , 255, 5);
345 nk_combo_end(ctx);
346 }
347 /* complex color combobox */
348 if (nk_combo_begin_color(ctx, nk_rgb_cf(combo_color2), nk_vec2(200,400))) {
349 enum color_mode {COL_RGB, COL_HSV};
350 static int col_mode = COL_RGB;
351 #ifndef DEMO_DO_NOT_USE_COLOR_PICKER
352 nk_layout_row_dynamic(ctx, 120, 1);
353 combo_color2 = nk_color_picker(ctx, combo_color2, NK_RGBA);
354 #endif
355
356 nk_layout_row_dynamic(ctx, 25, 2);
357 col_mode = nk_option_label(ctx, "RGB", col_mode == COL_RGB) ? COL_RGB : col_mode;
358 col_mode = nk_option_label(ctx, "HSV", col_mode == COL_HSV) ? COL_HSV : col_mode;
359
360 nk_layout_row_dynamic(ctx, 25, 1);
361 if (col_mode == COL_RGB) {
362 combo_color2.r = nk_propertyf(ctx, "#R:", 0, combo_color2.r, 1.0f, 0.01f,0.005f);
363 combo_color2.g = nk_propertyf(ctx, "#G:", 0, combo_color2.g, 1.0f, 0.01f,0.005f);
364 combo_color2.b = nk_propertyf(ctx, "#B:", 0, combo_color2.b, 1.0f, 0.01f,0.005f);
365 combo_color2.a = nk_propertyf(ctx, "#A:", 0, combo_color2.a, 1.0f, 0.01f,0.005f);
366 } else {
367 float hsva[4];
368 nk_colorf_hsva_fv(hsva, combo_color2);
369 hsva[0] = nk_propertyf(ctx, "#H:", 0, hsva[0], 1.0f, 0.01f,0.05f);
370 hsva[1] = nk_propertyf(ctx, "#S:", 0, hsva[1], 1.0f, 0.01f,0.05f);
371 hsva[2] = nk_propertyf(ctx, "#V:", 0, hsva[2], 1.0f, 0.01f,0.05f);
372 hsva[3] = nk_propertyf(ctx, "#A:", 0, hsva[3], 1.0f, 0.01f,0.05f);
373 combo_color2 = nk_hsva_colorfv(hsva);
374 }
375 nk_combo_end(ctx);
376 }
377 /* progressbar combobox */
378 sum = prog_a + prog_b + prog_c + prog_d;
379 sprintf(buffer, "%lu", sum);
380 if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) {
381 nk_layout_row_dynamic(ctx, 30, 1);
382 nk_progress(ctx, &prog_a, 100, NK_MODIFIABLE);
383 nk_progress(ctx, &prog_b, 100, NK_MODIFIABLE);
384 nk_progress(ctx, &prog_c, 100, NK_MODIFIABLE);
385 nk_progress(ctx, &prog_d, 100, NK_MODIFIABLE);
386 nk_combo_end(ctx);
387 }
388
389 /* checkbox combobox */
390 sum = (size_t)(check_values[0] + check_values[1] + check_values[2] + check_values[3] + check_values[4]);
391 sprintf(buffer, "%lu", sum);
392 if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) {
393 nk_layout_row_dynamic(ctx, 30, 1);
394 nk_checkbox_label(ctx, weapons[0], &check_values[0]);
395 nk_checkbox_label(ctx, weapons[1], &check_values[1]);
396 nk_checkbox_label(ctx, weapons[2], &check_values[2]);
397 nk_checkbox_label(ctx, weapons[3], &check_values[3]);
398 nk_combo_end(ctx);
399 }
400
401 /* complex text combobox */
402 sprintf(buffer, "%.2f, %.2f, %.2f", position[0], position[1],position[2]);
403 if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) {
404 nk_layout_row_dynamic(ctx, 25, 1);
405 nk_property_float(ctx, "#X:", -1024.0f, &position[0], 1024.0f, 1,0.5f);
406 nk_property_float(ctx, "#Y:", -1024.0f, &position[1], 1024.0f, 1,0.5f);
407 nk_property_float(ctx, "#Z:", -1024.0f, &position[2], 1024.0f, 1,0.5f);
408 nk_combo_end(ctx);
409 }
410
411 /* chart combobox */
412 sprintf(buffer, "%.1f", chart_selection);
413 if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,250))) {
414 size_t i = 0;
415 static const float values[]={26.0f,13.0f,30.0f,15.0f,25.0f,10.0f,20.0f,40.0f, 12.0f, 8.0f, 22.0f, 28.0f, 5.0f};
416 nk_layout_row_dynamic(ctx, 150, 1);
417 nk_chart_begin(ctx, NK_CHART_COLUMN, NK_LEN(values), 0, 50);
418 for (i = 0; i < NK_LEN(values); ++i) {
419 nk_flags res = nk_chart_push(ctx, values[i]);
420 if (res & NK_CHART_CLICKED) {
421 chart_selection = values[i];
422 nk_combo_close(ctx);
423 }
424 }
425 nk_chart_end(ctx);
426 nk_combo_end(ctx);
427 }
428
429 {
430 static int time_selected = 0;
431 static int date_selected = 0;
432 static struct tm sel_time;
433 static struct tm sel_date;
434 if (!time_selected || !date_selected) {
435 /* keep time and date updated if nothing is selected */
436 time_t cur_time = time(0);
437 struct tm *n = localtime(&cur_time);
438 if (!time_selected)
439 memcpy(&sel_time, n, sizeof(struct tm));
440 if (!date_selected)
441 memcpy(&sel_date, n, sizeof(struct tm));
442 }
443
444 /* time combobox */
445 sprintf(buffer, "%02d:%02d:%02d", sel_time.tm_hour, sel_time.tm_min, sel_time.tm_sec);
446 if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,250))) {
447 time_selected = 1;
448 nk_layout_row_dynamic(ctx, 25, 1);
449 sel_time.tm_sec = nk_propertyi(ctx, "#S:", 0, sel_time.tm_sec, 60, 1, 1);
450 sel_time.tm_min = nk_propertyi(ctx, "#M:", 0, sel_time.tm_min, 60, 1, 1);
451 sel_time.tm_hour = nk_propertyi(ctx, "#H:", 0, sel_time.tm_hour, 23, 1, 1);
452 nk_combo_end(ctx);
453 }
454
455 /* date combobox */
456 sprintf(buffer, "%02d-%02d-%02d", sel_date.tm_mday, sel_date.tm_mon+1, sel_date.tm_year+1900);
457 if (nk_combo_begin_label(ctx, buffer, nk_vec2(350,400)))
458 {
459 int i = 0;
460 const char *month[] = {"January", "February", "March",
461 "April", "May", "June", "July", "August", "September",
462 "October", "November", "December"};
463 const char *week_days[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
464 const int month_days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
465 int year = sel_date.tm_year+1900;
466 int leap_year = (!(year % 4) && ((year % 100))) || !(year % 400);
467 int days = (sel_date.tm_mon == 1) ?
468 month_days[sel_date.tm_mon] + leap_year:
469 month_days[sel_date.tm_mon];
470
471 /* header with month and year */
472 date_selected = 1;
473 nk_layout_row_begin(ctx, NK_DYNAMIC, 20, 3);
474 nk_layout_row_push(ctx, 0.05f);
475 if (nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_LEFT)) {
476 if (sel_date.tm_mon == 0) {
477 sel_date.tm_mon = 11;
478 sel_date.tm_year = NK_MAX(0, sel_date.tm_year-1);
479 } else sel_date.tm_mon--;
480 }
481 nk_layout_row_push(ctx, 0.9f);
482 sprintf(buffer, "%s %d", month[sel_date.tm_mon], year);
483 nk_label(ctx, buffer, NK_TEXT_CENTERED);
484 nk_layout_row_push(ctx, 0.05f);
485 if (nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT)) {
486 if (sel_date.tm_mon == 11) {
487 sel_date.tm_mon = 0;
488 sel_date.tm_year++;
489 } else sel_date.tm_mon++;
490 }
491 nk_layout_row_end(ctx);
492
493 /* good old week day formula (double because precision) */
494 {int year_n = (sel_date.tm_mon < 2) ? year-1: year;
495 int y = year_n % 100;
496 int c = year_n / 100;
497 int y4 = (int)((float)y / 4);
498 int c4 = (int)((float)c / 4);
499 int m = (int)(2.6 * (double)(((sel_date.tm_mon + 10) % 12) + 1) - 0.2);
500 int week_day = (((1 + m + y + y4 + c4 - 2 * c) % 7) + 7) % 7;
501
502 /* weekdays */
503 nk_layout_row_dynamic(ctx, 35, 7);
504 for (i = 0; i < (int)NK_LEN(week_days); ++i)
505 nk_label(ctx, week_days[i], NK_TEXT_CENTERED);
506
507 /* days */
508 if (week_day > 0) nk_spacing(ctx, week_day);
509 for (i = 1; i <= days; ++i) {
510 sprintf(buffer, "%d", i);
511 if (nk_button_label(ctx, buffer)) {
512 sel_date.tm_mday = i;
513 nk_combo_close(ctx);
514 }
515 }}
516 nk_combo_end(ctx);
517 }
518 }
519
520 nk_tree_pop(ctx);
521 }
522
523 if (nk_tree_push(ctx, NK_TREE_NODE, "Input", NK_MINIMIZED))
524 {
525 static const float ratio[] = {120, 150};
526 static char field_buffer[64];
527 static char text[9][64];
528 static int text_len[9];
529 static char box_buffer[512];
530 static int field_len;
531 static int box_len;
532 nk_flags active;
533
534 nk_layout_row(ctx, NK_STATIC, 25, 2, ratio);
535 nk_label(ctx, "Default:", NK_TEXT_LEFT);
536
537 nk_edit_string(ctx, NK_EDIT_SIMPLE, text[0], &text_len[0], 64, nk_filter_default);
538 nk_label(ctx, "Int:", NK_TEXT_LEFT);
539 nk_edit_string(ctx, NK_EDIT_SIMPLE, text[1], &text_len[1], 64, nk_filter_decimal);
540 nk_label(ctx, "Float:", NK_TEXT_LEFT);
541 nk_edit_string(ctx, NK_EDIT_SIMPLE, text[2], &text_len[2], 64, nk_filter_float);
542 nk_label(ctx, "Hex:", NK_TEXT_LEFT);
543 nk_edit_string(ctx, NK_EDIT_SIMPLE, text[4], &text_len[4], 64, nk_filter_hex);
544 nk_label(ctx, "Octal:", NK_TEXT_LEFT);
545 nk_edit_string(ctx, NK_EDIT_SIMPLE, text[5], &text_len[5], 64, nk_filter_oct);
546 nk_label(ctx, "Binary:", NK_TEXT_LEFT);
547 nk_edit_string(ctx, NK_EDIT_SIMPLE, text[6], &text_len[6], 64, nk_filter_binary);
548
549 nk_label(ctx, "Password:", NK_TEXT_LEFT);
550 {
551 int i = 0;
552 int old_len = text_len[8];
553 char buffer[64];
554 for (i = 0; i < text_len[8]; ++i) buffer[i] = '*';
555 nk_edit_string(ctx, NK_EDIT_FIELD, buffer, &text_len[8], 64, nk_filter_default);
556 if (old_len < text_len[8])
557 memcpy(&text[8][old_len], &buffer[old_len], (nk_size)(text_len[8] - old_len));
558 }
559
560 nk_label(ctx, "Field:", NK_TEXT_LEFT);
561 nk_edit_string(ctx, NK_EDIT_FIELD, field_buffer, &field_len, 64, nk_filter_default);
562
563 nk_label(ctx, "Box:", NK_TEXT_LEFT);
564 nk_layout_row_static(ctx, 180, 278, 1);
565 nk_edit_string(ctx, NK_EDIT_BOX, box_buffer, &box_len, 512, nk_filter_default);
566
567 nk_layout_row(ctx, NK_STATIC, 25, 2, ratio);
568 active = nk_edit_string(ctx, NK_EDIT_FIELD|NK_EDIT_SIG_ENTER, text[7], &text_len[7], 64, nk_filter_ascii);
569 if (nk_button_label(ctx, "Submit") ||
570 (active & NK_EDIT_COMMITED))
571 {
572 text[7][text_len[7]] = '\n';
573 text_len[7]++;
574 memcpy(&box_buffer[box_len], &text[7], (nk_size)text_len[7]);
575 box_len += text_len[7];
576 text_len[7] = 0;
577 }
578 nk_tree_pop(ctx);
579 }
580 nk_tree_pop(ctx);
581 }
582
583 if (nk_tree_push(ctx, NK_TREE_TAB, "Chart", NK_MINIMIZED))
584 {
585 /* Chart Widgets
586 * This library has two different rather simple charts. The line and the
587 * column chart. Both provide a simple way of visualizing values and
588 * have a retained mode and immediate mode API version. For the retain
589 * mode version `nk_plot` and `nk_plot_function` you either provide
590 * an array or a callback to call to handle drawing the graph.
591 * For the immediate mode version you start by calling `nk_chart_begin`
592 * and need to provide min and max values for scaling on the Y-axis.
593 * and then call `nk_chart_push` to push values into the chart.
594 * Finally `nk_chart_end` needs to be called to end the process. */
595 float id = 0;
596 static int col_index = -1;
597 static int line_index = -1;
598 float step = (2*3.141592654f) / 32;
599
600 int i;
601 int index = -1;
602 struct nk_rect bounds;
603
604 /* line chart */
605 id = 0;
606 index = -1;
607 nk_layout_row_dynamic(ctx, 100, 1);
608 bounds = nk_widget_bounds(ctx);
609 if (nk_chart_begin(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f)) {
610 for (i = 0; i < 32; ++i) {
611 nk_flags res = nk_chart_push(ctx, (float)cos(id));
612 if (res & NK_CHART_HOVERING)
613 index = (int)i;
614 if (res & NK_CHART_CLICKED)
615 line_index = (int)i;
616 id += step;
617 }
618 nk_chart_end(ctx);
619 }
620
621 if (index != -1)
622 nk_tooltipf(ctx, "Value: %.2f", (float)cos((float)index*step));
623 if (line_index != -1) {
624 nk_layout_row_dynamic(ctx, 20, 1);
625 nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", (float)cos((float)index*step));
626 }
627
628 /* column chart */
629 nk_layout_row_dynamic(ctx, 100, 1);
630 bounds = nk_widget_bounds(ctx);
631 if (nk_chart_begin(ctx, NK_CHART_COLUMN, 32, 0.0f, 1.0f)) {
632 for (i = 0; i < 32; ++i) {
633 nk_flags res = nk_chart_push(ctx, (float)fabs(sin(id)));
634 if (res & NK_CHART_HOVERING)
635 index = (int)i;
636 if (res & NK_CHART_CLICKED)
637 col_index = (int)i;
638 id += step;
639 }
640 nk_chart_end(ctx);
641 }
642 if (index != -1)
643 nk_tooltipf(ctx, "Value: %.2f", (float)fabs(sin(step * (float)index)));
644 if (col_index != -1) {
645 nk_layout_row_dynamic(ctx, 20, 1);
646 nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", (float)fabs(sin(step * (float)col_index)));
647 }
648
649 /* mixed chart */
650 nk_layout_row_dynamic(ctx, 100, 1);
651 bounds = nk_widget_bounds(ctx);
652 if (nk_chart_begin(ctx, NK_CHART_COLUMN, 32, 0.0f, 1.0f)) {
653 nk_chart_add_slot(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f);
654 nk_chart_add_slot(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f);
655 for (id = 0, i = 0; i < 32; ++i) {
656 nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
657 nk_chart_push_slot(ctx, (float)cos(id), 1);
658 nk_chart_push_slot(ctx, (float)sin(id), 2);
659 id += step;
660 }
661 }
662 nk_chart_end(ctx);
663
664 /* mixed colored chart */
665 nk_layout_row_dynamic(ctx, 100, 1);
666 bounds = nk_widget_bounds(ctx);
667 if (nk_chart_begin_colored(ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) {
668 nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f);
669 nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,255,0), nk_rgb(0,150,0), 32, -1.0f, 1.0f);
670 for (id = 0, i = 0; i < 32; ++i) {
671 nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
672 nk_chart_push_slot(ctx, (float)cos(id), 1);
673 nk_chart_push_slot(ctx, (float)sin(id), 2);
674 id += step;
675 }
676 }
677 nk_chart_end(ctx);
678 nk_tree_pop(ctx);
679 }
680
681 if (nk_tree_push(ctx, NK_TREE_TAB, "Popup", NK_MINIMIZED))
682 {
683 static struct nk_color color = {255,0,0, 255};
684 static int select[4];
685 static int popup_active;
686 const struct nk_input *in = &ctx->input;
687 struct nk_rect bounds;
688
689 /* menu contextual */
690 nk_layout_row_static(ctx, 30, 160, 1);
691 bounds = nk_widget_bounds(ctx);
692 nk_label(ctx, "Right click me for menu", NK_TEXT_LEFT);
693
694 if (nk_contextual_begin(ctx, 0, nk_vec2(100, 300), bounds)) {
695 static size_t prog = 40;
696 static int slider = 10;
697
698 nk_layout_row_dynamic(ctx, 25, 1);
699 nk_checkbox_label(ctx, "Menu", &show_menu);
700 nk_progress(ctx, &prog, 100, NK_MODIFIABLE);
701 nk_slider_int(ctx, 0, &slider, 16, 1);
702 if (nk_contextual_item_label(ctx, "About", NK_TEXT_CENTERED))
703 show_app_about = nk_true;
704 nk_selectable_label(ctx, select[0]?"Unselect":"Select", NK_TEXT_LEFT, &select[0]);
705 nk_selectable_label(ctx, select[1]?"Unselect":"Select", NK_TEXT_LEFT, &select[1]);
706 nk_selectable_label(ctx, select[2]?"Unselect":"Select", NK_TEXT_LEFT, &select[2]);
707 nk_selectable_label(ctx, select[3]?"Unselect":"Select", NK_TEXT_LEFT, &select[3]);
708 nk_contextual_end(ctx);
709 }
710
711 /* color contextual */
712 nk_layout_row_begin(ctx, NK_STATIC, 30, 2);
713 nk_layout_row_push(ctx, 100);
714 nk_label(ctx, "Right Click here:", NK_TEXT_LEFT);
715 nk_layout_row_push(ctx, 50);
716 bounds = nk_widget_bounds(ctx);
717 nk_button_color(ctx, color);
718 nk_layout_row_end(ctx);
719
720 if (nk_contextual_begin(ctx, 0, nk_vec2(350, 60), bounds)) {
721 nk_layout_row_dynamic(ctx, 30, 4);
722 color.r = (nk_byte)nk_propertyi(ctx, "#r", 0, color.r, 255, 1, 1);
723 color.g = (nk_byte)nk_propertyi(ctx, "#g", 0, color.g, 255, 1, 1);
724 color.b = (nk_byte)nk_propertyi(ctx, "#b", 0, color.b, 255, 1, 1);
725 color.a = (nk_byte)nk_propertyi(ctx, "#a", 0, color.a, 255, 1, 1);
726 nk_contextual_end(ctx);
727 }
728
729 /* popup */
730 nk_layout_row_begin(ctx, NK_STATIC, 30, 2);
731 nk_layout_row_push(ctx, 100);
732 nk_label(ctx, "Popup:", NK_TEXT_LEFT);
733 nk_layout_row_push(ctx, 50);
734 if (nk_button_label(ctx, "Popup"))
735 popup_active = 1;
736 nk_layout_row_end(ctx);
737
738 if (popup_active)
739 {
740 static struct nk_rect s = {20, 100, 220, 90};
741 if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Error", 0, s))
742 {
743 nk_layout_row_dynamic(ctx, 25, 1);
744 nk_label(ctx, "A terrible error as occured", NK_TEXT_LEFT);
745 nk_layout_row_dynamic(ctx, 25, 2);
746 if (nk_button_label(ctx, "OK")) {
747 popup_active = 0;
748 nk_popup_close(ctx);
749 }
750 if (nk_button_label(ctx, "Cancel")) {
751 popup_active = 0;
752 nk_popup_close(ctx);
753 }
754 nk_popup_end(ctx);
755 } else popup_active = nk_false;
756 }
757
758 /* tooltip */
759 nk_layout_row_static(ctx, 30, 150, 1);
760 bounds = nk_widget_bounds(ctx);
761 nk_label(ctx, "Hover me for tooltip", NK_TEXT_LEFT);
762 if (nk_input_is_mouse_hovering_rect(in, bounds))
763 nk_tooltip(ctx, "This is a tooltip");
764
765 nk_tree_pop(ctx);
766 }
767
768 if (nk_tree_push(ctx, NK_TREE_TAB, "Layout", NK_MINIMIZED))
769 {
770 if (nk_tree_push(ctx, NK_TREE_NODE, "Widget", NK_MINIMIZED))
771 {
772 float ratio_two[] = {0.2f, 0.6f, 0.2f};
773 float width_two[] = {100, 200, 50};
774
775 nk_layout_row_dynamic(ctx, 30, 1);
776 nk_label(ctx, "Dynamic fixed column layout with generated position and size:", NK_TEXT_LEFT);
777 nk_layout_row_dynamic(ctx, 30, 3);
778 nk_button_label(ctx, "button");
779 nk_button_label(ctx, "button");
780 nk_button_label(ctx, "button");
781
782 nk_layout_row_dynamic(ctx, 30, 1);
783 nk_label(ctx, "static fixed column layout with generated position and size:", NK_TEXT_LEFT);
784 nk_layout_row_static(ctx, 30, 100, 3);
785 nk_button_label(ctx, "button");
786 nk_button_label(ctx, "button");
787 nk_button_label(ctx, "button");
788
789 nk_layout_row_dynamic(ctx, 30, 1);
790 nk_label(ctx, "Dynamic array-based custom column layout with generated position and custom size:",NK_TEXT_LEFT);
791 nk_layout_row(ctx, NK_DYNAMIC, 30, 3, ratio_two);
792 nk_button_label(ctx, "button");
793 nk_button_label(ctx, "button");
794 nk_button_label(ctx, "button");
795
796 nk_layout_row_dynamic(ctx, 30, 1);
797 nk_label(ctx, "Static array-based custom column layout with generated position and custom size:",NK_TEXT_LEFT );
798 nk_layout_row(ctx, NK_STATIC, 30, 3, width_two);
799 nk_button_label(ctx, "button");
800 nk_button_label(ctx, "button");
801 nk_button_label(ctx, "button");
802
803 nk_layout_row_dynamic(ctx, 30, 1);
804 nk_label(ctx, "Dynamic immediate mode custom column layout with generated position and custom size:",NK_TEXT_LEFT);
805 nk_layout_row_begin(ctx, NK_DYNAMIC, 30, 3);
806 nk_layout_row_push(ctx, 0.2f);
807 nk_button_label(ctx, "button");
808 nk_layout_row_push(ctx, 0.6f);
809 nk_button_label(ctx, "button");
810 nk_layout_row_push(ctx, 0.2f);
811 nk_button_label(ctx, "button");
812 nk_layout_row_end(ctx);
813
814 nk_layout_row_dynamic(ctx, 30, 1);
815 nk_label(ctx, "Static immediate mode custom column layout with generated position and custom size:", NK_TEXT_LEFT);
816 nk_layout_row_begin(ctx, NK_STATIC, 30, 3);
817 nk_layout_row_push(ctx, 100);
818 nk_button_label(ctx, "button");
819 nk_layout_row_push(ctx, 200);
820 nk_button_label(ctx, "button");
821 nk_layout_row_push(ctx, 50);
822 nk_button_label(ctx, "button");
823 nk_layout_row_end(ctx);
824
825 nk_layout_row_dynamic(ctx, 30, 1);
826 nk_label(ctx, "Static free space with custom position and custom size:", NK_TEXT_LEFT);
827 nk_layout_space_begin(ctx, NK_STATIC, 60, 4);
828 nk_layout_space_push(ctx, nk_rect(100, 0, 100, 30));
829 nk_button_label(ctx, "button");
830 nk_layout_space_push(ctx, nk_rect(0, 15, 100, 30));
831 nk_button_label(ctx, "button");
832 nk_layout_space_push(ctx, nk_rect(200, 15, 100, 30));
833 nk_button_label(ctx, "button");
834 nk_layout_space_push(ctx, nk_rect(100, 30, 100, 30));
835 nk_button_label(ctx, "button");
836 nk_layout_space_end(ctx);
837
838 nk_layout_row_dynamic(ctx, 30, 1);
839 nk_label(ctx, "Row template:", NK_TEXT_LEFT);
840 nk_layout_row_template_begin(ctx, 30);
841 nk_layout_row_template_push_dynamic(ctx);
842 nk_layout_row_template_push_variable(ctx, 80);
843 nk_layout_row_template_push_static(ctx, 80);
844 nk_layout_row_template_end(ctx);
845 nk_button_label(ctx, "button");
846 nk_button_label(ctx, "button");
847 nk_button_label(ctx, "button");
848
849 nk_tree_pop(ctx);
850 }
851
852 if (nk_tree_push(ctx, NK_TREE_NODE, "Group", NK_MINIMIZED))
853 {
854 static int group_titlebar = nk_false;
855 static int group_border = nk_true;
856 static int group_no_scrollbar = nk_false;
857 static int group_width = 320;
858 static int group_height = 200;
859
860 nk_flags group_flags = 0;
861 if (group_border) group_flags |= NK_WINDOW_BORDER;
862 if (group_no_scrollbar) group_flags |= NK_WINDOW_NO_SCROLLBAR;
863 if (group_titlebar) group_flags |= NK_WINDOW_TITLE;
864
865 nk_layout_row_dynamic(ctx, 30, 3);
866 nk_checkbox_label(ctx, "Titlebar", &group_titlebar);
867 nk_checkbox_label(ctx, "Border", &group_border);
868 nk_checkbox_label(ctx, "No Scrollbar", &group_no_scrollbar);
869
870 nk_layout_row_begin(ctx, NK_STATIC, 22, 3);
871 nk_layout_row_push(ctx, 50);
872 nk_label(ctx, "size:", NK_TEXT_LEFT);
873 nk_layout_row_push(ctx, 130);
874 nk_property_int(ctx, "#Width:", 100, &group_width, 500, 10, 1);
875 nk_layout_row_push(ctx, 130);
876 nk_property_int(ctx, "#Height:", 100, &group_height, 500, 10, 1);
877 nk_layout_row_end(ctx);
878
879 nk_layout_row_static(ctx, (float)group_height, group_width, 2);
880 if (nk_group_begin(ctx, "Group", group_flags)) {
881 int i = 0;
882 static int selected[16];
883 nk_layout_row_static(ctx, 18, 100, 1);
884 for (i = 0; i < 16; ++i)
885 nk_selectable_label(ctx, (selected[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected[i]);
886 nk_group_end(ctx);
887 }
888 nk_tree_pop(ctx);
889 }
890
891 if (nk_tree_push(ctx, NK_TREE_NODE, "Notebook", NK_MINIMIZED))
892 {
893 static int current_tab = 0;
894 struct nk_rect bounds;
895 float step = (2*3.141592654f) / 32;
896 enum chart_type {CHART_LINE, CHART_HISTO, CHART_MIXED};
897 const char *names[] = {"Lines", "Columns", "Mixed"};
898 float id = 0;
899 int i;
900
901 /* Header */
902 nk_style_push_vec2(ctx, &ctx->style.window.spacing, nk_vec2(0,0));
903 nk_style_push_float(ctx, &ctx->style.button.rounding, 0);
904 nk_layout_row_begin(ctx, NK_STATIC, 20, 3);
905 for (i = 0; i < 3; ++i) {
906 /* make sure button perfectly fits text */
907 const struct nk_user_font *f = ctx->style.font;
908 float text_width = f->width(f->userdata, f->height, names[i], nk_strlen(names[i]));
909 float widget_width = text_width + 3 * ctx->style.button.padding.x;
910 nk_layout_row_push(ctx, widget_width);
911 if (current_tab == i) {
912 /* active tab gets highlighted */
913 struct nk_style_item button_color = ctx->style.button.normal;
914 ctx->style.button.normal = ctx->style.button.active;
915 current_tab = nk_button_label(ctx, names[i]) ? i: current_tab;
916 ctx->style.button.normal = button_color;
917 } else current_tab = nk_button_label(ctx, names[i]) ? i: current_tab;
918 }
919 nk_style_pop_float(ctx);
920
921 /* Body */
922 nk_layout_row_dynamic(ctx, 140, 1);
923 if (nk_group_begin(ctx, "Notebook", NK_WINDOW_BORDER))
924 {
925 nk_style_pop_vec2(ctx);
926 switch (current_tab) {
927 default: break;
928 case CHART_LINE:
929 nk_layout_row_dynamic(ctx, 100, 1);
930 bounds = nk_widget_bounds(ctx);
931 if (nk_chart_begin_colored(ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) {
932 nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f);
933 for (i = 0, id = 0; i < 32; ++i) {
934 nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
935 nk_chart_push_slot(ctx, (float)cos(id), 1);
936 id += step;
937 }
938 }
939 nk_chart_end(ctx);
940 break;
941 case CHART_HISTO:
942 nk_layout_row_dynamic(ctx, 100, 1);
943 bounds = nk_widget_bounds(ctx);
944 if (nk_chart_begin_colored(ctx, NK_CHART_COLUMN, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) {
945 for (i = 0, id = 0; i < 32; ++i) {
946 nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
947 id += step;
948 }
949 }
950 nk_chart_end(ctx);
951 break;
952 case CHART_MIXED:
953 nk_layout_row_dynamic(ctx, 100, 1);
954 bounds = nk_widget_bounds(ctx);
955 if (nk_chart_begin_colored(ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) {
956 nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f);
957 nk_chart_add_slot_colored(ctx, NK_CHART_COLUMN, nk_rgb(0,255,0), nk_rgb(0,150,0), 32, 0.0f, 1.0f);
958 for (i = 0, id = 0; i < 32; ++i) {
959 nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
960 nk_chart_push_slot(ctx, (float)fabs(cos(id)), 1);
961 nk_chart_push_slot(ctx, (float)fabs(sin(id)), 2);
962 id += step;
963 }
964 }
965 nk_chart_end(ctx);
966 break;
967 }
968 nk_group_end(ctx);
969 } else nk_style_pop_vec2(ctx);
970 nk_tree_pop(ctx);
971 }
972
973 if (nk_tree_push(ctx, NK_TREE_NODE, "Simple", NK_MINIMIZED))
974 {
975 nk_layout_row_dynamic(ctx, 300, 2);
976 if (nk_group_begin(ctx, "Group_Without_Border", 0)) {
977 int i = 0;
978 char buffer[64];
979 nk_layout_row_static(ctx, 18, 150, 1);
980 for (i = 0; i < 64; ++i) {
981 sprintf(buffer, "0x%02x", i);
982 nk_labelf(ctx, NK_TEXT_LEFT, "%s: scrollable region", buffer);
983 }
984 nk_group_end(ctx);
985 }
986 if (nk_group_begin(ctx, "Group_With_Border", NK_WINDOW_BORDER)) {
987 int i = 0;
988 char buffer[64];
989 nk_layout_row_dynamic(ctx, 25, 2);
990 for (i = 0; i < 64; ++i) {
991 sprintf(buffer, "%08d", ((((i%7)*10)^32))+(64+(i%2)*2));
992 nk_button_label(ctx, buffer);
993 }
994 nk_group_end(ctx);
995 }
996 nk_tree_pop(ctx);
997 }
998
999 if (nk_tree_push(ctx, NK_TREE_NODE, "Complex", NK_MINIMIZED))
1000 {
1001 int i;
1002 nk_layout_space_begin(ctx, NK_STATIC, 500, 64);
1003 nk_layout_space_push(ctx, nk_rect(0,0,150,500));
1004 if (nk_group_begin(ctx, "Group_left", NK_WINDOW_BORDER)) {
1005 static int selected[32];
1006 nk_layout_row_static(ctx, 18, 100, 1);
1007 for (i = 0; i < 32; ++i)
1008 nk_selectable_label(ctx, (selected[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected[i]);
1009 nk_group_end(ctx);
1010 }
1011
1012 nk_layout_space_push(ctx, nk_rect(160,0,150,240));
1013 if (nk_group_begin(ctx, "Group_top", NK_WINDOW_BORDER)) {
1014 nk_layout_row_dynamic(ctx, 25, 1);
1015 nk_button_label(ctx, "#FFAA");
1016 nk_button_label(ctx, "#FFBB");
1017 nk_button_label(ctx, "#FFCC");
1018 nk_button_label(ctx, "#FFDD");
1019 nk_button_label(ctx, "#FFEE");
1020 nk_button_label(ctx, "#FFFF");
1021 nk_group_end(ctx);
1022 }
1023
1024 nk_layout_space_push(ctx, nk_rect(160,250,150,250));
1025 if (nk_group_begin(ctx, "Group_buttom", NK_WINDOW_BORDER)) {
1026 nk_layout_row_dynamic(ctx, 25, 1);
1027 nk_button_label(ctx, "#FFAA");
1028 nk_button_label(ctx, "#FFBB");
1029 nk_button_label(ctx, "#FFCC");
1030 nk_button_label(ctx, "#FFDD");
1031 nk_button_label(ctx, "#FFEE");
1032 nk_button_label(ctx, "#FFFF");
1033 nk_group_end(ctx);
1034 }
1035
1036 nk_layout_space_push(ctx, nk_rect(320,0,150,150));
1037 if (nk_group_begin(ctx, "Group_right_top", NK_WINDOW_BORDER)) {
1038 static int selected[4];
1039 nk_layout_row_static(ctx, 18, 100, 1);
1040 for (i = 0; i < 4; ++i)
1041 nk_selectable_label(ctx, (selected[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected[i]);
1042 nk_group_end(ctx);
1043 }
1044
1045 nk_layout_space_push(ctx, nk_rect(320,160,150,150));
1046 if (nk_group_begin(ctx, "Group_right_center", NK_WINDOW_BORDER)) {
1047 static int selected[4];
1048 nk_layout_row_static(ctx, 18, 100, 1);
1049 for (i = 0; i < 4; ++i)
1050 nk_selectable_label(ctx, (selected[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected[i]);
1051 nk_group_end(ctx);
1052 }
1053
1054 nk_layout_space_push(ctx, nk_rect(320,320,150,150));
1055 if (nk_group_begin(ctx, "Group_right_bottom", NK_WINDOW_BORDER)) {
1056 static int selected[4];
1057 nk_layout_row_static(ctx, 18, 100, 1);
1058 for (i = 0; i < 4; ++i)
1059 nk_selectable_label(ctx, (selected[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected[i]);
1060 nk_group_end(ctx);
1061 }
1062 nk_layout_space_end(ctx);
1063 nk_tree_pop(ctx);
1064 }
1065
1066 if (nk_tree_push(ctx, NK_TREE_NODE, "Splitter", NK_MINIMIZED))
1067 {
1068 const struct nk_input *in = &ctx->input;
1069 nk_layout_row_static(ctx, 20, 320, 1);
1070 nk_label(ctx, "Use slider and spinner to change tile size", NK_TEXT_LEFT);
1071 nk_label(ctx, "Drag the space between tiles to change tile ratio", NK_TEXT_LEFT);
1072
1073 if (nk_tree_push(ctx, NK_TREE_NODE, "Vertical", NK_MINIMIZED))
1074 {
1075 static float a = 100, b = 100, c = 100;
1076 struct nk_rect bounds;
1077
1078 float row_layout[5];
1079 row_layout[0] = a;
1080 row_layout[1] = 8;
1081 row_layout[2] = b;
1082 row_layout[3] = 8;
1083 row_layout[4] = c;
1084
1085 /* header */
1086 nk_layout_row_static(ctx, 30, 100, 2);
1087 nk_label(ctx, "left:", NK_TEXT_LEFT);
1088 nk_slider_float(ctx, 10.0f, &a, 200.0f, 10.0f);
1089
1090 nk_label(ctx, "middle:", NK_TEXT_LEFT);
1091 nk_slider_float(ctx, 10.0f, &b, 200.0f, 10.0f);
1092
1093 nk_label(ctx, "right:", NK_TEXT_LEFT);
1094 nk_slider_float(ctx, 10.0f, &c, 200.0f, 10.0f);
1095
1096 /* tiles */
1097 nk_layout_row(ctx, NK_STATIC, 200, 5, row_layout);
1098
1099 /* left space */
1100 if (nk_group_begin(ctx, "left", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
1101 nk_layout_row_dynamic(ctx, 25, 1);
1102 nk_button_label(ctx, "#FFAA");
1103 nk_button_label(ctx, "#FFBB");
1104 nk_button_label(ctx, "#FFCC");
1105 nk_button_label(ctx, "#FFDD");
1106 nk_button_label(ctx, "#FFEE");
1107 nk_button_label(ctx, "#FFFF");
1108 nk_group_end(ctx);
1109 }
1110
1111 /* scaler */
1112 bounds = nk_widget_bounds(ctx);
1113 nk_spacing(ctx, 1);
1114 if ((nk_input_is_mouse_hovering_rect(in, bounds) ||
1115 nk_input_is_mouse_prev_hovering_rect(in, bounds)) &&
1116 nk_input_is_mouse_down(in, NK_BUTTON_LEFT))
1117 {
1118 a = row_layout[0] + in->mouse.delta.x;
1119 b = row_layout[2] - in->mouse.delta.x;
1120 }
1121
1122 /* middle space */
1123 if (nk_group_begin(ctx, "center", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
1124 nk_layout_row_dynamic(ctx, 25, 1);
1125 nk_button_label(ctx, "#FFAA");
1126 nk_button_label(ctx, "#FFBB");
1127 nk_button_label(ctx, "#FFCC");
1128 nk_button_label(ctx, "#FFDD");
1129 nk_button_label(ctx, "#FFEE");
1130 nk_button_label(ctx, "#FFFF");
1131 nk_group_end(ctx);
1132 }
1133
1134 /* scaler */
1135 bounds = nk_widget_bounds(ctx);
1136 nk_spacing(ctx, 1);
1137 if ((nk_input_is_mouse_hovering_rect(in, bounds) ||
1138 nk_input_is_mouse_prev_hovering_rect(in, bounds)) &&
1139 nk_input_is_mouse_down(in, NK_BUTTON_LEFT))
1140 {
1141 b = (row_layout[2] + in->mouse.delta.x);
1142 c = (row_layout[4] - in->mouse.delta.x);
1143 }
1144
1145 /* right space */
1146 if (nk_group_begin(ctx, "right", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
1147 nk_layout_row_dynamic(ctx, 25, 1);
1148 nk_button_label(ctx, "#FFAA");
1149 nk_button_label(ctx, "#FFBB");
1150 nk_button_label(ctx, "#FFCC");
1151 nk_button_label(ctx, "#FFDD");
1152 nk_button_label(ctx, "#FFEE");
1153 nk_button_label(ctx, "#FFFF");
1154 nk_group_end(ctx);
1155 }
1156
1157 nk_tree_pop(ctx);
1158 }
1159
1160 if (nk_tree_push(ctx, NK_TREE_NODE, "Horizontal", NK_MINIMIZED))
1161 {
1162 static float a = 100, b = 100, c = 100;
1163 struct nk_rect bounds;
1164
1165 /* header */
1166 nk_layout_row_static(ctx, 30, 100, 2);
1167 nk_label(ctx, "top:", NK_TEXT_LEFT);
1168 nk_slider_float(ctx, 10.0f, &a, 200.0f, 10.0f);
1169
1170 nk_label(ctx, "middle:", NK_TEXT_LEFT);
1171 nk_slider_float(ctx, 10.0f, &b, 200.0f, 10.0f);
1172
1173 nk_label(ctx, "bottom:", NK_TEXT_LEFT);
1174 nk_slider_float(ctx, 10.0f, &c, 200.0f, 10.0f);
1175
1176 /* top space */
1177 nk_layout_row_dynamic(ctx, a, 1);
1178 if (nk_group_begin(ctx, "top", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
1179 nk_layout_row_dynamic(ctx, 25, 3);
1180 nk_button_label(ctx, "#FFAA");
1181 nk_button_label(ctx, "#FFBB");
1182 nk_button_label(ctx, "#FFCC");
1183 nk_button_label(ctx, "#FFDD");
1184 nk_button_label(ctx, "#FFEE");
1185 nk_button_label(ctx, "#FFFF");
1186 nk_group_end(ctx);
1187 }
1188
1189 /* scaler */
1190 nk_layout_row_dynamic(ctx, 8, 1);
1191 bounds = nk_widget_bounds(ctx);
1192 nk_spacing(ctx, 1);
1193 if ((nk_input_is_mouse_hovering_rect(in, bounds) ||
1194 nk_input_is_mouse_prev_hovering_rect(in, bounds)) &&
1195 nk_input_is_mouse_down(in, NK_BUTTON_LEFT))
1196 {
1197 a = a + in->mouse.delta.y;
1198 b = b - in->mouse.delta.y;
1199 }
1200
1201 /* middle space */
1202 nk_layout_row_dynamic(ctx, b, 1);
1203 if (nk_group_begin(ctx, "middle", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
1204 nk_layout_row_dynamic(ctx, 25, 3);
1205 nk_button_label(ctx, "#FFAA");
1206 nk_button_label(ctx, "#FFBB");
1207 nk_button_label(ctx, "#FFCC");
1208 nk_button_label(ctx, "#FFDD");
1209 nk_button_label(ctx, "#FFEE");
1210 nk_button_label(ctx, "#FFFF");
1211 nk_group_end(ctx);
1212 }
1213
1214 {
1215 /* scaler */
1216 nk_layout_row_dynamic(ctx, 8, 1);
1217 bounds = nk_widget_bounds(ctx);
1218 if ((nk_input_is_mouse_hovering_rect(in, bounds) ||
1219 nk_input_is_mouse_prev_hovering_rect(in, bounds)) &&
1220 nk_input_is_mouse_down(in, NK_BUTTON_LEFT))
1221 {
1222 b = b + in->mouse.delta.y;
1223 c = c - in->mouse.delta.y;
1224 }
1225 }
1226
1227 /* bottom space */
1228 nk_layout_row_dynamic(ctx, c, 1);
1229 if (nk_group_begin(ctx, "bottom", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) {
1230 nk_layout_row_dynamic(ctx, 25, 3);
1231 nk_button_label(ctx, "#FFAA");
1232 nk_button_label(ctx, "#FFBB");
1233 nk_button_label(ctx, "#FFCC");
1234 nk_button_label(ctx, "#FFDD");
1235 nk_button_label(ctx, "#FFEE");
1236 nk_button_label(ctx, "#FFFF");
1237 nk_group_end(ctx);
1238 }
1239 nk_tree_pop(ctx);
1240 }
1241 nk_tree_pop(ctx);
1242 }
1243 nk_tree_pop(ctx);
1244 }
1245 }
1246 nk_end(ctx);
1247 return !nk_window_is_closed(ctx, "Overview");
1248 }
1249
1250