overview.c 66 KB

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