overview.c 63 KB

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