overview.c 66 KB

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