overview.c 63 KB

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