overview.c 66 KB

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