overview.c 58 KB

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