Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

Style Configuration Tool RFC

Open rswinkle opened this issue 5 years ago • 8 comments

I made this for myself it working on my own Nuklear projects and also to help me understand how the various styles work and interact.

I think it (and the individual functions) would be useful to others both for app developers and developing and debugging Nuklear itself. I could also see adding more configuration for values that aren't (currently) exposed in the style structures but figured I'd leave that for future work.

While I've been testing it manually/informally while I've written it, there was a lot of copy/pasting involved so I'm sure it's inevitable that a few bugs slipped through, which is why this is marked as a RFC. I definitely want people to try it on more backends (I tested on sdl_opengl3), but also just want general suggestions/critiques.

rswinkle avatar Mar 07 '20 20:03 rswinkle

I'm not 100% done but it looks like you were almost exactly right. Even without getting rid of the comments I could probably get it down to an even 1000. And really I'm on the fence about the comments, they definitely stand out more in a semi-bad way now that it's shorter and cleaner.

rswinkle avatar Mar 09 '20 09:03 rswinkle

Btw, just ping me when you feel the code is ready for another review. I'll then take a look and get this merged.

Hejsil avatar Apr 01 '20 18:04 Hejsil

There's not really anything else to do but I'm in no hurry to merge it. We might as well wait till after your nk_slice/API change so you'll have one less demo to worry about updating yourself. Plus it'll give me practice with the new changes.

rswinkle avatar Apr 05 '20 07:04 rswinkle

Awesome job - getting a few warnings and compile errors when I include the c file into my c++ sources (it works for the other demos):

../../src/tests/testnuklear/style_configurator.c:179:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  179 |  for (int i=0; i<NK_LEN(aligns); ++i) {
../../src/tests/testnuklear/style_configurator.c:180:29: warning: comparison of integer expressions of different signedness: ‘nk_flags’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
  180 |   if (button.text_alignment == aligns[i]) {
      |       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
../../src/tests/testnuklear/style_configurator.c: In function ‘void style_slider(nk_context*, nk_style_slider*)’:
../../src/tests/testnuklear/style_configurator.c:293:31: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  293 |   slider.inc_symbol = nk_combo(ctx, symbols, (int)NK_SYMBOL_MAX, slider.inc_symbol, 25, nk_vec2(200,200));
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               int
../../src/tests/testnuklear/style_configurator.c:295:31: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  295 |   slider.dec_symbol = nk_combo(ctx, symbols, (int)NK_SYMBOL_MAX, slider.dec_symbol, 25, nk_vec2(200,200));
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               int
In file included from ../../src/tests/testnuklear/TestNuklear.cpp:17:
../../src/tests/testnuklear/style_configurator.c: In function ‘void style_scrollbars(nk_context*, nk_style_scrollbar*, nk_style_scrollbar**, int)’:
../../src/tests/testnuklear/style_configurator.c:373:31: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  373 |   scroll.inc_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, scroll.inc_symbol, 25, nk_vec2(200,200));
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               int
../../src/tests/testnuklear/style_configurator.c:375:31: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  375 |   scroll.dec_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, scroll.dec_symbol, 25, nk_vec2(200,200));
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               int
../../src/tests/testnuklear/style_configurator.c: In function ‘void style_property(nk_context*, nk_style_property*)’:
../../src/tests/testnuklear/style_configurator.c:456:30: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  456 |  property.sym_left = nk_combo(ctx, symbols, NK_SYMBOL_MAX, property.sym_left, 25, nk_vec2(200,200));
      |                      ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              |
      |                              int
../../src/tests/testnuklear/style_configurator.c:458:31: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  458 |  property.sym_right = nk_combo(ctx, symbols, NK_SYMBOL_MAX, property.sym_right, 25, nk_vec2(200,200));
      |                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               int
../../src/tests/testnuklear/style_configurator.c: In function ‘void style_combo(nk_context*, nk_style_combo*)’:
../../src/tests/testnuklear/style_configurator.c:512:29: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  512 |  combo.sym_normal = nk_combo(ctx, symbols, NK_SYMBOL_MAX, combo.sym_normal, 25, nk_vec2(200,200));
      |                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                             |
      |                             int
../../src/tests/testnuklear/style_configurator.c:514:28: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  514 |  combo.sym_hover = nk_combo(ctx, symbols, NK_SYMBOL_MAX, combo.sym_hover, 25, nk_vec2(200,200));
      |                    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            |
      |                            int
../../src/tests/testnuklear/style_configurator.c:516:29: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  516 |  combo.sym_active = nk_combo(ctx, symbols, NK_SYMBOL_MAX, combo.sym_active, 25, nk_vec2(200,200));
      |                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                             |
      |                             int
../../src/tests/testnuklear/style_configurator.c: In function ‘void style_tab(nk_context*, nk_style_tab*)’:
../../src/tests/testnuklear/style_configurator.c:543:29: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  543 |  tab.sym_minimize = nk_combo(ctx, symbols, NK_SYMBOL_MAX, tab.sym_minimize, 25, nk_vec2(200,200));
      |                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                             |
      |                             int
../../src/tests/testnuklear/style_configurator.c:545:29: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  545 |  tab.sym_maximize = nk_combo(ctx, symbols, NK_SYMBOL_MAX, tab.sym_maximize, 25, nk_vec2(200,200));
      |                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                             |
      |                             int
../../src/tests/testnuklear/style_configurator.c: In function ‘void style_window_header(nk_context*, nk_style_window_header*)’:
../../src/tests/testnuklear/style_configurator.c:583:25: error: invalid conversion from ‘int’ to ‘nk_style_header_align’ [-fpermissive]
  583 |  header.align = nk_combo(ctx, alignments, NUM_ALIGNS, header.align, 25, nk_vec2(200,200));
      |                 ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         |
      |                         int
../../src/tests/testnuklear/style_configurator.c:587:32: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  587 |  header.close_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, header.close_symbol, 25, nk_vec2(200,200));
      |                        ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                |
      |                                int
../../src/tests/testnuklear/style_configurator.c:589:35: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  589 |  header.minimize_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, header.minimize_symbol, 25, nk_vec2(200,200));
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                   |
      |                                   int
../../src/tests/testnuklear/style_configurator.c:591:35: error: invalid conversion from ‘int’ to ‘nk_symbol_type’ [-fpermissive]
  591 |  header.maximize_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, header.maximize_symbol, 25, nk_vec2(200,200));
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                   |
      |                                   int

mgerhardy avatar Apr 08 '20 16:04 mgerhardy

nk_default_color_style is used to reset the colors ("Reset all styles to defaults") - maybe it would be better to reset to the colors given as parameter to style_configurator? Just a suggestion.

mgerhardy avatar Apr 08 '20 16:04 mgerhardy

@riri thanks for looking into this! I generally agree though I would leave the C99 as it is (though I would definitely keep -pedantic -Wall). Anybody can rewrite it to C89 later after the merge :wink:.

@rswinkle let us know once you feel this is OK to be reviewed for the merge. Thanks a ton!

dumblob avatar Mar 29 '23 08:03 dumblob

Let me know if there's anything else but it's pretty much done.

rswinkle avatar Mar 29 '23 17:03 rswinkle

LGTM, tested on Linux (sdl/opengl3 backend). If fixes are needed for other demos, they can surely be done afterwards.

Thanks again for this tool, I will certainly play with it soon (and probably request improvements ^^)

riri avatar Apr 29 '23 16:04 riri