overview.c 58 KB

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