style_configurator.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /*
  2. TODO design decisions
  3. plural or not? ie style_button or style_buttons?
  4. use the duplicate array method, or just let the user
  5. manually set those after calling the function by accessing ctx->style->*?
  6. */
  7. static const char* symbols[NK_SYMBOL_MAX] =
  8. {
  9. "NONE",
  10. "X",
  11. "UNDERSCORE",
  12. "CIRCLE_SOLID",
  13. "CIRCLE_OUTLINE",
  14. "RECT_SOLID",
  15. "RECT_OUTLINE",
  16. "TRIANGLE_UP",
  17. "TRIANGLE_DOWN",
  18. "TRIANGLE_LEFT",
  19. "TRIANGLE_RIGHT",
  20. "PLUS",
  21. "MINUS"
  22. };
  23. static int
  24. style_rgb(struct nk_context* ctx, const char* name, struct nk_color* color)
  25. {
  26. struct nk_colorf colorf;
  27. nk_label(ctx, name, NK_TEXT_LEFT);
  28. if (nk_combo_begin_color(ctx, *color, nk_vec2(nk_widget_width(ctx), 400))) {
  29. nk_layout_row_dynamic(ctx, 120, 1);
  30. colorf = nk_color_picker(ctx, nk_color_cf(*color), NK_RGB);
  31. nk_layout_row_dynamic(ctx, 25, 1);
  32. colorf.r = nk_propertyf(ctx, "#R:", 0, colorf.r, 1.0f, 0.01f,0.005f);
  33. colorf.g = nk_propertyf(ctx, "#G:", 0, colorf.g, 1.0f, 0.01f,0.005f);
  34. colorf.b = nk_propertyf(ctx, "#B:", 0, colorf.b, 1.0f, 0.01f,0.005f);
  35. *color = nk_rgb_cf(colorf);
  36. nk_combo_end(ctx);
  37. return 1;
  38. }
  39. return 0;
  40. }
  41. /* TODO style_style_item? how to handle images if at all? */
  42. static void
  43. style_item_color(struct nk_context* ctx, const char* name, struct nk_style_item* item)
  44. {
  45. style_rgb(ctx, name, &item->data.color);
  46. }
  47. static void
  48. style_vec2(struct nk_context* ctx, const char* name, struct nk_vec2* vec)
  49. {
  50. char buffer[64];
  51. nk_label(ctx, name, NK_TEXT_LEFT);
  52. sprintf(buffer, "%.2f, %.2f", vec->x, vec->y);
  53. if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) {
  54. nk_layout_row_dynamic(ctx, 25, 1);
  55. nk_property_float(ctx, "#X:", -100.0f, &vec->x, 100.0f, 1,0.5f);
  56. nk_property_float(ctx, "#Y:", -100.0f, &vec->y, 100.0f, 1,0.5f);
  57. nk_combo_end(ctx);
  58. }
  59. }
  60. /* style_general? pass array in instead of static? */
  61. static void
  62. style_global_colors(struct nk_context* ctx, struct nk_color color_table[NK_COLOR_COUNT])
  63. {
  64. const char* color_labels[NK_COLOR_COUNT] =
  65. {
  66. "COLOR_TEXT:",
  67. "COLOR_WINDOW:",
  68. "COLOR_HEADER:",
  69. "COLOR_BORDER:",
  70. "COLOR_BUTTON:",
  71. "COLOR_BUTTON_HOVER:",
  72. "COLOR_BUTTON_ACTIVE:",
  73. "COLOR_TOGGLE:",
  74. "COLOR_TOGGLE_HOVER:",
  75. "COLOR_TOGGLE_CURSOR:",
  76. "COLOR_SELECT:",
  77. "COLOR_SELECT_ACTIVE:",
  78. "COLOR_SLIDER:",
  79. "COLOR_SLIDER_CURSOR:",
  80. "COLOR_SLIDER_CURSOR_HOVER:",
  81. "COLOR_SLIDER_CURSOR_ACTIVE:",
  82. "COLOR_PROPERTY:",
  83. "COLOR_EDIT:",
  84. "COLOR_EDIT_CURSOR:",
  85. "COLOR_COMBO:",
  86. "COLOR_CHART:",
  87. "COLOR_CHART_COLOR:",
  88. "COLOR_CHART_COLOR_HIGHLIGHT:",
  89. "COLOR_SCROLLBAR:",
  90. "COLOR_SCROLLBAR_CURSOR:",
  91. "COLOR_SCROLLBAR_CURSOR_HOVER:",
  92. "COLOR_SCROLLBAR_CURSOR_ACTIVE:",
  93. "COLOR_TAB_HEADER:",
  94. "COLOR_KNOB:",
  95. "COLOR_KNOB_CURSOR:",
  96. "COLOR_KNOB_CURSOR_HOVER:",
  97. "COLOR_KNOB_CURSOR_ACTIVE:"
  98. };
  99. int clicked = 0;
  100. int i;
  101. nk_layout_row_dynamic(ctx, 30, 2);
  102. for (i=0; i<NK_COLOR_COUNT; ++i) {
  103. clicked |= style_rgb(ctx, color_labels[i], &color_table[i]);
  104. }
  105. if (clicked) {
  106. nk_style_from_table(ctx, color_table);
  107. }
  108. }
  109. static void
  110. style_text(struct nk_context* ctx, struct nk_style_text* out_style)
  111. {
  112. struct nk_style_text text = *out_style;
  113. nk_layout_row_dynamic(ctx, 30, 2);
  114. style_rgb(ctx, "Color:", &text.color);
  115. style_vec2(ctx, "Padding:", &text.padding);
  116. *out_style = text;
  117. }
  118. static void
  119. style_button(struct nk_context* ctx, struct nk_style_button* out_style, struct nk_style_button** duplicate_styles, int n_dups)
  120. {
  121. struct nk_style_button button = *out_style;
  122. nk_layout_row_dynamic(ctx, 30, 2);
  123. style_item_color(ctx, "Normal:", &button.normal);
  124. style_item_color(ctx, "Hover:", &button.hover);
  125. style_item_color(ctx, "Active:", &button.active);
  126. style_rgb(ctx, "Border:", &button.border_color);
  127. style_rgb(ctx, "Text Background:", &button.text_background);
  128. style_rgb(ctx, "Text Normal:", &button.text_normal);
  129. style_rgb(ctx, "Text Hover:", &button.text_hover);
  130. style_rgb(ctx, "Text Active:", &button.text_active);
  131. style_vec2(ctx, "Padding:", &button.padding);
  132. style_vec2(ctx, "Image Padding:", &button.image_padding);
  133. style_vec2(ctx, "Touch Padding:", &button.touch_padding);
  134. {
  135. const char* alignments[] =
  136. {
  137. "LEFT",
  138. "CENTERED",
  139. "RIGHT",
  140. "TOP LEFT",
  141. "TOP CENTERED",
  142. "TOP_RIGHT",
  143. "BOTTOM LEFT",
  144. "BOTTOM CENTERED",
  145. "BOTTOM RIGHT"
  146. };
  147. #define TOP_LEFT NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_LEFT
  148. #define TOP_CENTER NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_CENTERED
  149. #define TOP_RIGHT NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_RIGHT
  150. #define BOTTOM_LEFT NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_LEFT
  151. #define BOTTOM_CENTER NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_CENTERED
  152. #define BOTTOM_RIGHT NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_RIGHT
  153. unsigned int aligns[] =
  154. {
  155. NK_TEXT_LEFT,
  156. NK_TEXT_CENTERED,
  157. NK_TEXT_RIGHT,
  158. TOP_LEFT,
  159. TOP_CENTER,
  160. TOP_RIGHT,
  161. BOTTOM_LEFT,
  162. BOTTOM_CENTER,
  163. BOTTOM_RIGHT
  164. };
  165. int cur_align = button.text_alignment-NK_TEXT_LEFT;
  166. int i;
  167. for (i=0; i<(int)NK_LEN(aligns); ++i) {
  168. if (button.text_alignment == aligns[i]) {
  169. cur_align = i;
  170. break;
  171. }
  172. }
  173. nk_label(ctx, "Text Alignment:", NK_TEXT_LEFT);
  174. cur_align = nk_combo(ctx, alignments, NK_LEN(alignments), cur_align, 25, nk_vec2(200,200));
  175. button.text_alignment = aligns[cur_align];
  176. nk_property_float(ctx, "#Border:", -100.0f, &button.border, 100.0f, 1,0.5f);
  177. nk_property_float(ctx, "#Rounding:", -100.0f, &button.rounding, 100.0f, 1,0.5f);
  178. *out_style = button;
  179. if (duplicate_styles) {
  180. int i;
  181. for (i=0; i<n_dups; ++i) {
  182. *duplicate_styles[i] = button;
  183. }
  184. }
  185. }
  186. }
  187. static void style_toggle(struct nk_context* ctx, struct nk_style_toggle* out_style)
  188. {
  189. struct nk_style_toggle toggle = *out_style;
  190. nk_layout_row_dynamic(ctx, 30, 2);
  191. style_item_color(ctx, "Normal:", &toggle.normal);
  192. style_item_color(ctx, "Hover:", &toggle.hover);
  193. style_item_color(ctx, "Active:", &toggle.active);
  194. style_item_color(ctx, "Cursor Normal:", &toggle.cursor_normal);
  195. style_item_color(ctx, "Cursor Hover:", &toggle.cursor_hover);
  196. style_rgb(ctx, "Border:", &toggle.border_color);
  197. style_rgb(ctx, "Text Background:", &toggle.text_background);
  198. style_rgb(ctx, "Text Normal:", &toggle.text_normal);
  199. style_rgb(ctx, "Text Hover:", &toggle.text_hover);
  200. style_rgb(ctx, "Text Active:", &toggle.text_active);
  201. style_vec2(ctx, "Padding:", &toggle.padding);
  202. style_vec2(ctx, "Touch Padding:", &toggle.touch_padding);
  203. nk_property_float(ctx, "#Border:", -100.0f, &toggle.border, 100.0f, 1,0.5f);
  204. nk_property_float(ctx, "#Spacing:", -100.0f, &toggle.spacing, 100.0f, 1,0.5f);
  205. *out_style = toggle;
  206. }
  207. static void
  208. style_selectable(struct nk_context* ctx, struct nk_style_selectable* out_style)
  209. {
  210. struct nk_style_selectable select = *out_style;
  211. nk_layout_row_dynamic(ctx, 30, 2);
  212. style_item_color(ctx, "Normal:", &select.normal);
  213. style_item_color(ctx, "Hover:", &select.hover);
  214. style_item_color(ctx, "Pressed:", &select.pressed);
  215. style_item_color(ctx, "Normal Active:", &select.normal_active);
  216. style_item_color(ctx, "Hover Active:", &select.hover_active);
  217. style_item_color(ctx, "Pressed Active:", &select.pressed_active);
  218. style_rgb(ctx, "Text Normal:", &select.text_normal);
  219. style_rgb(ctx, "Text Hover:", &select.text_hover);
  220. style_rgb(ctx, "Text Pressed:", &select.text_pressed);
  221. style_rgb(ctx, "Text Normal Active:", &select.text_normal_active);
  222. style_rgb(ctx, "Text Hover Active:", &select.text_hover_active);
  223. style_rgb(ctx, "Text Pressed Active:", &select.text_pressed_active);
  224. style_vec2(ctx, "Padding:", &select.padding);
  225. style_vec2(ctx, "Image Padding:", &select.image_padding);
  226. style_vec2(ctx, "Touch Padding:", &select.touch_padding);
  227. nk_property_float(ctx, "#Rounding:", -100.0f, &select.rounding, 100.0f, 1,0.5f);
  228. *out_style = select;
  229. }
  230. static void
  231. style_slider(struct nk_context* ctx, struct nk_style_slider* out_style)
  232. {
  233. struct nk_style_slider slider = *out_style;
  234. struct nk_style_button* dups[1];
  235. nk_layout_row_dynamic(ctx, 30, 2);
  236. style_item_color(ctx, "Normal:", &slider.normal);
  237. style_item_color(ctx, "Hover:", &slider.hover);
  238. style_item_color(ctx, "Active:", &slider.active);
  239. style_rgb(ctx, "Bar Normal:", &slider.bar_normal);
  240. style_rgb(ctx, "Bar Hover:", &slider.bar_hover);
  241. style_rgb(ctx, "Bar Active:", &slider.bar_active);
  242. style_rgb(ctx, "Bar Filled:", &slider.bar_filled);
  243. style_item_color(ctx, "Cursor Normal:", &slider.cursor_normal);
  244. style_item_color(ctx, "Cursor Hover:", &slider.cursor_hover);
  245. style_item_color(ctx, "Cursor Active:", &slider.cursor_active);
  246. style_vec2(ctx, "Cursor Size:", &slider.cursor_size);
  247. style_vec2(ctx, "Padding:", &slider.padding);
  248. style_vec2(ctx, "Spacing:", &slider.spacing);
  249. nk_property_float(ctx, "#Bar Height:", -100.0f, &slider.bar_height, 100.0f, 1,0.5f);
  250. nk_property_float(ctx, "#Rounding:", -100.0f, &slider.rounding, 100.0f, 1,0.5f);
  251. nk_layout_row_dynamic(ctx, 30, 1);
  252. nk_checkbox_label(ctx, "Show Buttons", &slider.show_buttons);
  253. if (slider.show_buttons) {
  254. nk_layout_row_dynamic(ctx, 30, 2);
  255. nk_label(ctx, "Inc Symbol:", NK_TEXT_LEFT);
  256. slider.inc_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, slider.inc_symbol, 25, nk_vec2(200,200));
  257. nk_label(ctx, "Dec Symbol:", NK_TEXT_LEFT);
  258. slider.dec_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, slider.dec_symbol, 25, nk_vec2(200,200));
  259. /* necessary or do tree's always take the whole width? */
  260. /* nk_layout_row_dynamic(ctx, 30, 1); */
  261. if (nk_tree_push(ctx, NK_TREE_TAB, "Slider Buttons", NK_MINIMIZED)) {
  262. dups[0] = &ctx->style.slider.dec_button;
  263. style_button(ctx, &ctx->style.slider.inc_button, dups, 1);
  264. nk_tree_pop(ctx);
  265. }
  266. }
  267. *out_style = slider;
  268. }
  269. static void
  270. style_progress(struct nk_context* ctx, struct nk_style_progress* out_style)
  271. {
  272. struct nk_style_progress prog = *out_style;
  273. nk_layout_row_dynamic(ctx, 30, 2);
  274. style_item_color(ctx, "Normal:", &prog.normal);
  275. style_item_color(ctx, "Hover:", &prog.hover);
  276. style_item_color(ctx, "Active:", &prog.active);
  277. style_item_color(ctx, "Cursor Normal:", &prog.cursor_normal);
  278. style_item_color(ctx, "Cursor Hover:", &prog.cursor_hover);
  279. style_item_color(ctx, "Cursor Active:", &prog.cursor_active);
  280. /* TODO rgba? */
  281. style_rgb(ctx, "Border Color:", &prog.border_color);
  282. style_rgb(ctx, "Cursor Border Color:", &prog.cursor_border_color);
  283. style_vec2(ctx, "Padding:", &prog.padding);
  284. nk_property_float(ctx, "#Rounding:", -100.0f, &prog.rounding, 100.0f, 1,0.5f);
  285. nk_property_float(ctx, "#Border:", -100.0f, &prog.border, 100.0f, 1,0.5f);
  286. nk_property_float(ctx, "#Cursor Rounding:", -100.0f, &prog.cursor_rounding, 100.0f, 1,0.5f);
  287. nk_property_float(ctx, "#Cursor Border:", -100.0f, &prog.cursor_border, 100.0f, 1,0.5f);
  288. *out_style = prog;
  289. }
  290. static void
  291. style_scrollbars(struct nk_context* ctx, struct nk_style_scrollbar* out_style, struct nk_style_scrollbar** duplicate_styles, int n_dups)
  292. {
  293. struct nk_style_scrollbar scroll = *out_style;
  294. struct nk_style_button* dups[3];
  295. nk_layout_row_dynamic(ctx, 30, 2);
  296. style_item_color(ctx, "Normal:", &scroll.normal);
  297. style_item_color(ctx, "Hover:", &scroll.hover);
  298. style_item_color(ctx, "Active:", &scroll.active);
  299. style_item_color(ctx, "Cursor Normal:", &scroll.cursor_normal);
  300. style_item_color(ctx, "Cursor Hover:", &scroll.cursor_hover);
  301. style_item_color(ctx, "Cursor Active:", &scroll.cursor_active);
  302. /* TODO rgba? */
  303. style_rgb(ctx, "Border Color:", &scroll.border_color);
  304. style_rgb(ctx, "Cursor Border Color:", &scroll.cursor_border_color);
  305. style_vec2(ctx, "Padding:", &scroll.padding);
  306. nk_property_float(ctx, "#Border:", -100.0f, &scroll.border, 100.0f, 1,0.5f);
  307. nk_property_float(ctx, "#Rounding:", -100.0f, &scroll.rounding, 100.0f, 1,0.5f);
  308. /* TODO naming inconsistency with style_scrollress? */
  309. nk_property_float(ctx, "#Cursor Border:", -100.0f, &scroll.border_cursor, 100.0f, 1,0.5f);
  310. nk_property_float(ctx, "#Cursor Rounding:", -100.0f, &scroll.rounding_cursor, 100.0f, 1,0.5f);
  311. /* TODO what is wrong with scrollbar buttons? Also look into controlling the total width (and height) of scrollbars */
  312. nk_layout_row_dynamic(ctx, 30, 1);
  313. nk_checkbox_label(ctx, "Show Buttons", &scroll.show_buttons);
  314. if (scroll.show_buttons) {
  315. nk_layout_row_dynamic(ctx, 30, 2);
  316. nk_label(ctx, "Inc Symbol:", NK_TEXT_LEFT);
  317. scroll.inc_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, scroll.inc_symbol, 25, nk_vec2(200,200));
  318. nk_label(ctx, "Dec Symbol:", NK_TEXT_LEFT);
  319. scroll.dec_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, scroll.dec_symbol, 25, nk_vec2(200,200));
  320. /* nk_layout_row_dynamic(ctx, 30, 1); */
  321. if (nk_tree_push(ctx, NK_TREE_TAB, "Scrollbar Buttons", NK_MINIMIZED)) {
  322. dups[0] = &ctx->style.scrollh.dec_button;
  323. dups[1] = &ctx->style.scrollv.inc_button;
  324. dups[2] = &ctx->style.scrollv.dec_button;
  325. style_button(ctx, &ctx->style.scrollh.inc_button, dups, 3);
  326. nk_tree_pop(ctx);
  327. }
  328. }
  329. *out_style = scroll;
  330. if (duplicate_styles) {
  331. int i;
  332. for (i=0; i<n_dups; ++i) {
  333. *duplicate_styles[i] = scroll;
  334. }
  335. }
  336. }
  337. static void
  338. style_edit(struct nk_context* ctx, struct nk_style_edit* out_style)
  339. {
  340. struct nk_style_edit edit = *out_style;
  341. nk_layout_row_dynamic(ctx, 30, 2);
  342. style_item_color(ctx, "Normal:", &edit.normal);
  343. style_item_color(ctx, "Hover:", &edit.hover);
  344. style_item_color(ctx, "Active:", &edit.active);
  345. style_rgb(ctx, "Cursor Normal:", &edit.cursor_normal);
  346. style_rgb(ctx, "Cursor Hover:", &edit.cursor_hover);
  347. style_rgb(ctx, "Cursor Text Normal:", &edit.cursor_text_normal);
  348. style_rgb(ctx, "Cursor Text Hover:", &edit.cursor_text_hover);
  349. style_rgb(ctx, "Border:", &edit.border_color);
  350. style_rgb(ctx, "Text Normal:", &edit.text_normal);
  351. style_rgb(ctx, "Text Hover:", &edit.text_hover);
  352. style_rgb(ctx, "Text Active:", &edit.text_active);
  353. style_rgb(ctx, "Selected Normal:", &edit.selected_normal);
  354. style_rgb(ctx, "Selected Hover:", &edit.selected_hover);
  355. style_rgb(ctx, "Selected Text Normal:", &edit.selected_text_normal);
  356. style_rgb(ctx, "Selected Text Hover:", &edit.selected_text_hover);
  357. style_vec2(ctx, "Scrollbar Size:", &edit.scrollbar_size);
  358. style_vec2(ctx, "Padding:", &edit.padding);
  359. nk_property_float(ctx, "#Row Padding:", -100.0f, &edit.row_padding, 100.0f, 1,0.5f);
  360. nk_property_float(ctx, "#Cursor Size:", -100.0f, &edit.cursor_size, 100.0f, 1,0.5f);
  361. nk_property_float(ctx, "#Border:", -100.0f, &edit.border, 100.0f, 1,0.5f);
  362. nk_property_float(ctx, "#Rounding:", -100.0f, &edit.rounding, 100.0f, 1,0.5f);
  363. *out_style = edit;
  364. }
  365. static void
  366. style_property(struct nk_context* ctx, struct nk_style_property* out_style)
  367. {
  368. struct nk_style_property property = *out_style;
  369. struct nk_style_button* dups[1];
  370. nk_layout_row_dynamic(ctx, 30, 2);
  371. style_item_color(ctx, "Normal:", &property.normal);
  372. style_item_color(ctx, "Hover:", &property.hover);
  373. style_item_color(ctx, "Active:", &property.active);
  374. style_rgb(ctx, "Border:", &property.border_color);
  375. style_rgb(ctx, "Label Normal:", &property.label_normal);
  376. style_rgb(ctx, "Label Hover:", &property.label_hover);
  377. style_rgb(ctx, "Label Active:", &property.label_active);
  378. style_vec2(ctx, "Padding:", &property.padding);
  379. /* TODO check weird hover bug with properties, happens in overview basic section too */
  380. nk_property_float(ctx, "#Border:", -100.0f, &property.border, 100.0f, 1,0.5f);
  381. nk_property_float(ctx, "#Rounding:", -100.0f, &property.rounding, 100.0f, 1,0.5f);
  382. /* there is no property.show_buttons, they're always there */
  383. nk_label(ctx, "Left Symbol:", NK_TEXT_LEFT);
  384. property.sym_left = nk_combo(ctx, symbols, NK_SYMBOL_MAX, property.sym_left, 25, nk_vec2(200,200));
  385. nk_label(ctx, "Right Symbol:", NK_TEXT_LEFT);
  386. property.sym_right = nk_combo(ctx, symbols, NK_SYMBOL_MAX, property.sym_right, 25, nk_vec2(200,200));
  387. if (nk_tree_push(ctx, NK_TREE_TAB, "Property Buttons", NK_MINIMIZED)) {
  388. dups[0] = &property.dec_button;
  389. style_button(ctx, &property.inc_button, dups, 1);
  390. nk_tree_pop(ctx);
  391. }
  392. if (nk_tree_push(ctx, NK_TREE_TAB, "Property Edit", NK_MINIMIZED)) {
  393. style_edit(ctx, &ctx->style.property.edit);
  394. nk_tree_pop(ctx);
  395. }
  396. *out_style = property;
  397. }
  398. static void
  399. style_chart(struct nk_context* ctx, struct nk_style_chart* out_style)
  400. {
  401. struct nk_style_chart chart = *out_style;
  402. nk_layout_row_dynamic(ctx, 30, 2);
  403. style_item_color(ctx, "Background:", &chart.background);
  404. style_rgb(ctx, "Border:", &chart.border_color);
  405. style_rgb(ctx, "Selected Color:", &chart.selected_color);
  406. style_rgb(ctx, "Color:", &chart.color);
  407. style_vec2(ctx, "Padding:", &chart.padding);
  408. nk_property_float(ctx, "#Border:", -100.0f, &chart.border, 100.0f, 1,0.5f);
  409. nk_property_float(ctx, "#Rounding:", -100.0f, &chart.rounding, 100.0f, 1,0.5f);
  410. *out_style = chart;
  411. }
  412. static void
  413. style_combo(struct nk_context* ctx, struct nk_style_combo* out_style)
  414. {
  415. struct nk_style_combo combo = *out_style;
  416. nk_layout_row_dynamic(ctx, 30, 2);
  417. style_item_color(ctx, "Normal:", &combo.normal);
  418. style_item_color(ctx, "Hover:", &combo.hover);
  419. style_item_color(ctx, "Active:", &combo.active);
  420. style_rgb(ctx, "Border:", &combo.border_color);
  421. style_rgb(ctx, "Label Normal:", &combo.label_normal);
  422. style_rgb(ctx, "Label Hover:", &combo.label_hover);
  423. style_rgb(ctx, "Label Active:", &combo.label_active);
  424. nk_label(ctx, "Normal Symbol:", NK_TEXT_LEFT);
  425. combo.sym_normal = nk_combo(ctx, symbols, NK_SYMBOL_MAX, combo.sym_normal, 25, nk_vec2(200,200));
  426. nk_label(ctx, "Hover Symbol:", NK_TEXT_LEFT);
  427. combo.sym_hover = nk_combo(ctx, symbols, NK_SYMBOL_MAX, combo.sym_hover, 25, nk_vec2(200,200));
  428. nk_label(ctx, "Active Symbol:", NK_TEXT_LEFT);
  429. combo.sym_active = nk_combo(ctx, symbols, NK_SYMBOL_MAX, combo.sym_active, 25, nk_vec2(200,200));
  430. style_vec2(ctx, "Content Padding:", &combo.content_padding);
  431. style_vec2(ctx, "Button Padding:", &combo.button_padding);
  432. style_vec2(ctx, "Spacing:", &combo.spacing);
  433. nk_property_float(ctx, "#Border:", -100.0f, &combo.border, 100.0f, 1,0.5f);
  434. nk_property_float(ctx, "#Rounding:", -100.0f, &combo.rounding, 100.0f, 1,0.5f);
  435. *out_style = combo;
  436. }
  437. static void
  438. style_tab(struct nk_context* ctx, struct nk_style_tab* out_style)
  439. {
  440. struct nk_style_tab tab = *out_style;
  441. nk_layout_row_dynamic(ctx, 30, 2);
  442. style_item_color(ctx, "Background:", &tab.background);
  443. style_rgb(ctx, "Border:", &tab.border_color);
  444. style_rgb(ctx, "Text:", &tab.text);
  445. /*
  446. * FTR, I feel these fields are misnamed and should be sym_minimized and sym_maximized since they are
  447. * what show in that state, not the button to push to get to that state
  448. */
  449. nk_label(ctx, "Minimized Symbol:", NK_TEXT_LEFT);
  450. tab.sym_minimize = nk_combo(ctx, symbols, NK_SYMBOL_MAX, tab.sym_minimize, 25, nk_vec2(200,200));
  451. nk_label(ctx, "Maxmized Symbol:", NK_TEXT_LEFT);
  452. tab.sym_maximize = nk_combo(ctx, symbols, NK_SYMBOL_MAX, tab.sym_maximize, 25, nk_vec2(200,200));
  453. style_vec2(ctx, "Padding:", &tab.padding);
  454. style_vec2(ctx, "Spacing:", &tab.spacing);
  455. nk_property_float(ctx, "#Indent:", -100.0f, &tab.indent, 100.0f, 1,0.5f);
  456. nk_property_float(ctx, "#Border:", -100.0f, &tab.border, 100.0f, 1,0.5f);
  457. nk_property_float(ctx, "#Rounding:", -100.0f, &tab.rounding, 100.0f, 1,0.5f);
  458. *out_style = tab;
  459. }
  460. static void
  461. style_window_header(struct nk_context* ctx, struct nk_style_window_header* out_style)
  462. {
  463. struct nk_style_window_header header = *out_style;
  464. struct nk_style_button* dups[1];
  465. nk_layout_row_dynamic(ctx, 30, 2);
  466. style_item_color(ctx, "Normal:", &header.normal);
  467. style_item_color(ctx, "Hover:", &header.hover);
  468. style_item_color(ctx, "Active:", &header.active);
  469. style_rgb(ctx, "Label Normal:", &header.label_normal);
  470. style_rgb(ctx, "Label Hover:", &header.label_hover);
  471. style_rgb(ctx, "Label Active:", &header.label_active);
  472. style_vec2(ctx, "Label Padding:", &header.label_padding);
  473. style_vec2(ctx, "Padding:", &header.padding);
  474. style_vec2(ctx, "Spacing:", &header.spacing);
  475. #define NUM_ALIGNS 2
  476. {
  477. const char* alignments[NUM_ALIGNS] = { "LEFT", "RIGHT" };
  478. nk_layout_row_dynamic(ctx, 30, 2);
  479. nk_label(ctx, "Button Alignment:", NK_TEXT_LEFT);
  480. header.align = nk_combo(ctx, alignments, NUM_ALIGNS, header.align, 25, nk_vec2(200,200));
  481. }
  482. #undef NUM_ALIGNS
  483. nk_label(ctx, "Close Symbol:", NK_TEXT_LEFT);
  484. header.close_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, header.close_symbol, 25, nk_vec2(200,200));
  485. nk_label(ctx, "Minimize Symbol:", NK_TEXT_LEFT);
  486. header.minimize_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, header.minimize_symbol, 25, nk_vec2(200,200));
  487. nk_label(ctx, "Maximize Symbol:", NK_TEXT_LEFT);
  488. header.maximize_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, header.maximize_symbol, 25, nk_vec2(200,200));
  489. /* necessary or do tree's always take the whole width? */
  490. /* nk_layout_row_dynamic(ctx, 30, 1); */
  491. if (nk_tree_push(ctx, NK_TREE_TAB, "Close and Minimize Button", NK_MINIMIZED)) {
  492. dups[0] = &header.minimize_button;
  493. style_button(ctx, &header.close_button, dups, 1);
  494. nk_tree_pop(ctx);
  495. }
  496. *out_style = header;
  497. }
  498. static void
  499. style_window(struct nk_context* ctx, struct nk_style_window* out_style)
  500. {
  501. struct nk_style_window win = *out_style;
  502. nk_layout_row_dynamic(ctx, 30, 2);
  503. style_rgb(ctx, "Background:", &win.background);
  504. style_item_color(ctx, "Fixed Background:", &win.fixed_background);
  505. style_rgb(ctx, "Border:", &win.border_color);
  506. style_rgb(ctx, "Popup Border:", &win.popup_border_color);
  507. style_rgb(ctx, "Combo Border:", &win.combo_border_color);
  508. style_rgb(ctx, "Contextual Border:", &win.contextual_border_color);
  509. style_rgb(ctx, "Menu Border:", &win.menu_border_color);
  510. style_rgb(ctx, "Group Border:", &win.group_border_color);
  511. style_rgb(ctx, "Tooltip Border:", &win.tooltip_border_color);
  512. style_item_color(ctx, "Scaler:", &win.scaler);
  513. style_vec2(ctx, "Spacing:", &win.spacing);
  514. style_vec2(ctx, "Scrollbar Size:", &win.scrollbar_size);
  515. style_vec2(ctx, "Min Size:", &win.min_size);
  516. style_vec2(ctx, "Padding:", &win.padding);
  517. style_vec2(ctx, "Group Padding:", &win.group_padding);
  518. style_vec2(ctx, "Popup Padding:", &win.popup_padding);
  519. style_vec2(ctx, "Combo Padding:", &win.combo_padding);
  520. style_vec2(ctx, "Contextual Padding:", &win.contextual_padding);
  521. style_vec2(ctx, "Menu Padding:", &win.menu_padding);
  522. style_vec2(ctx, "Tooltip Padding:", &win.tooltip_padding);
  523. nk_property_float(ctx, "#Rounding:", -100.0f, &win.rounding, 100.0f, 1,0.5f);
  524. nk_property_float(ctx, "#Combo Border:", -100.0f, &win.combo_border, 100.0f, 1,0.5f);
  525. nk_property_float(ctx, "#Contextual Border:", -100.0f, &win.contextual_border, 100.0f, 1,0.5f);
  526. nk_property_float(ctx, "#Menu Border:", -100.0f, &win.menu_border, 100.0f, 1,0.5f);
  527. nk_property_float(ctx, "#Group Border:", -100.0f, &win.group_border, 100.0f, 1,0.5f);
  528. nk_property_float(ctx, "#Tooltip Border:", -100.0f, &win.tooltip_border, 100.0f, 1,0.5f);
  529. nk_property_float(ctx, "#Popup Border:", -100.0f, &win.popup_border, 100.0f, 1,0.5f);
  530. nk_property_float(ctx, "#Border:", -100.0f, &win.border, 100.0f, 1,0.5f);
  531. nk_layout_row_dynamic(ctx, 30, 1);
  532. nk_property_float(ctx, "#Min Row Height Padding:", -100.0f, &win.min_row_height_padding, 100.0f, 1,0.5f);
  533. if (nk_tree_push(ctx, NK_TREE_TAB, "Window Header", NK_MINIMIZED)) {
  534. style_window_header(ctx, &win.header);
  535. nk_tree_pop(ctx);
  536. }
  537. *out_style = win;
  538. }
  539. static int
  540. style_configurator(struct nk_context *ctx, struct nk_color color_table[NK_COLOR_COUNT])
  541. {
  542. /* window flags */
  543. int border = nk_true;
  544. int resize = nk_true;
  545. int movable = nk_true;
  546. int no_scrollbar = nk_false;
  547. int scale_left = nk_false;
  548. nk_flags window_flags = 0;
  549. int minimizable = nk_true;
  550. struct nk_style *style = NULL;
  551. struct nk_style_button* dups[1];
  552. /* window flags */
  553. window_flags = 0;
  554. if (border) window_flags |= NK_WINDOW_BORDER;
  555. if (resize) window_flags |= NK_WINDOW_SCALABLE;
  556. if (movable) window_flags |= NK_WINDOW_MOVABLE;
  557. if (no_scrollbar) window_flags |= NK_WINDOW_NO_SCROLLBAR;
  558. if (scale_left) window_flags |= NK_WINDOW_SCALE_LEFT;
  559. if (minimizable) window_flags |= NK_WINDOW_MINIMIZABLE;
  560. style = &ctx->style;
  561. if (nk_begin(ctx, "Configurator", nk_rect(10, 10, 400, 600), window_flags))
  562. {
  563. if (nk_tree_push(ctx, NK_TREE_TAB, "Global Colors", NK_MINIMIZED)) {
  564. style_global_colors(ctx, color_table);
  565. nk_tree_pop(ctx);
  566. }
  567. if (nk_tree_push(ctx, NK_TREE_TAB, "Text", NK_MINIMIZED)) {
  568. style_text(ctx, &style->text);
  569. nk_tree_pop(ctx);
  570. }
  571. if (nk_tree_push(ctx, NK_TREE_TAB, "Button", NK_MINIMIZED)) {
  572. style_button(ctx, &style->button, NULL, 0);
  573. nk_tree_pop(ctx);
  574. }
  575. if (nk_tree_push(ctx, NK_TREE_TAB, "Contextual Button", NK_MINIMIZED)) {
  576. style_button(ctx, &style->contextual_button, NULL, 0);
  577. nk_tree_pop(ctx);
  578. }
  579. if (nk_tree_push(ctx, NK_TREE_TAB, "Menu Button", NK_MINIMIZED)) {
  580. style_button(ctx, &style->menu_button, NULL, 0);
  581. nk_tree_pop(ctx);
  582. }
  583. if (nk_tree_push(ctx, NK_TREE_TAB, "Combo Buttons", NK_MINIMIZED)) {
  584. style_button(ctx, &style->combo.button, NULL, 0);
  585. nk_tree_pop(ctx);
  586. }
  587. if (nk_tree_push(ctx, NK_TREE_TAB, "Tab Min/Max Buttons", NK_MINIMIZED)) {
  588. dups[0] = &style->tab.tab_maximize_button;
  589. style_button(ctx, &style->tab.tab_minimize_button, dups, 1);
  590. nk_tree_pop(ctx);
  591. }
  592. if (nk_tree_push(ctx, NK_TREE_TAB, "Node Min/Max Buttons", NK_MINIMIZED)) {
  593. dups[0] = &style->tab.node_maximize_button;
  594. style_button(ctx, &style->tab.node_minimize_button, dups, 1);
  595. nk_tree_pop(ctx);
  596. }
  597. if (nk_tree_push(ctx, NK_TREE_TAB, "Window Header Close Buttons", NK_MINIMIZED)) {
  598. style_button(ctx, &style->window.header.close_button, NULL, 0);
  599. nk_tree_pop(ctx);
  600. }
  601. if (nk_tree_push(ctx, NK_TREE_TAB, "Window Header Minimize Buttons", NK_MINIMIZED)) {
  602. style_button(ctx, &style->window.header.minimize_button, NULL, 0);
  603. nk_tree_pop(ctx);
  604. }
  605. if (nk_tree_push(ctx, NK_TREE_TAB, "Checkbox", NK_MINIMIZED)) {
  606. style_toggle(ctx, &style->checkbox);
  607. nk_tree_pop(ctx);
  608. }
  609. if (nk_tree_push(ctx, NK_TREE_TAB, "Option", NK_MINIMIZED)) {
  610. style_toggle(ctx, &style->option);
  611. nk_tree_pop(ctx);
  612. }
  613. if (nk_tree_push(ctx, NK_TREE_TAB, "Selectable", NK_MINIMIZED)) {
  614. style_selectable(ctx, &style->selectable);
  615. nk_tree_pop(ctx);
  616. }
  617. if (nk_tree_push(ctx, NK_TREE_TAB, "Slider", NK_MINIMIZED)) {
  618. style_slider(ctx, &style->slider);
  619. nk_tree_pop(ctx);
  620. }
  621. if (nk_tree_push(ctx, NK_TREE_TAB, "Progress", NK_MINIMIZED)) {
  622. style_progress(ctx, &style->progress);
  623. nk_tree_pop(ctx);
  624. }
  625. if (nk_tree_push(ctx, NK_TREE_TAB, "Scrollbars", NK_MINIMIZED)) {
  626. struct nk_style_scrollbar* dups[1];
  627. dups[0] = &style->scrollv;
  628. style_scrollbars(ctx, &style->scrollh, dups, 1);
  629. nk_tree_pop(ctx);
  630. }
  631. if (nk_tree_push(ctx, NK_TREE_TAB, "Edit", NK_MINIMIZED)) {
  632. style_edit(ctx, &style->edit);
  633. nk_tree_pop(ctx);
  634. }
  635. if (nk_tree_push(ctx, NK_TREE_TAB, "Property", NK_MINIMIZED)) {
  636. style_property(ctx, &style->property);
  637. nk_tree_pop(ctx);
  638. }
  639. if (nk_tree_push(ctx, NK_TREE_TAB, "Chart", NK_MINIMIZED)) {
  640. style_chart(ctx, &style->chart);
  641. nk_tree_pop(ctx);
  642. }
  643. if (nk_tree_push(ctx, NK_TREE_TAB, "Combo", NK_MINIMIZED)) {
  644. style_combo(ctx, &style->combo);
  645. nk_tree_pop(ctx);
  646. }
  647. if (nk_tree_push(ctx, NK_TREE_TAB, "Tab", NK_MINIMIZED)) {
  648. style_tab(ctx, &style->tab);
  649. nk_tree_pop(ctx);
  650. }
  651. if (nk_tree_push(ctx, NK_TREE_TAB, "Window", NK_MINIMIZED)) {
  652. style_window(ctx, &style->window);
  653. nk_tree_pop(ctx);
  654. }
  655. nk_layout_row_dynamic(ctx, 30, 1);
  656. if (nk_button_label(ctx, "Reset all styles to defaults")) {
  657. memcpy(color_table, nk_default_color_style, sizeof(nk_default_color_style));
  658. nk_style_default(ctx);
  659. }
  660. }
  661. nk_end(ctx);
  662. return !nk_window_is_closed(ctx, "Configurator");
  663. }