vurtun / nuklear

A single-header ANSI C gui library
13.69k stars 1.11k forks source link

Style of combobox buttons should be set automatically within nuklear rather than set manually by the user #843

Open BenjiBoy926 opened 5 years ago

BenjiBoy926 commented 5 years ago

I am currently working with comboboxes in nuklear and was a little thrown off by the fact that the styles of the buttons in the combobox dropdown are not automatically set to the member variable button in the struct nk_style_combo

This is the code I was using before:

void Render_COMBOBOX(
COMBOBOX* combobox, struct nk_context* ctx, int height, struct nk_vec2 size) {

        ctx->style.combo = combobox->style;

    nk_combobox(
    ctx, (const char**)combobox->items, combobox->totalItems,
    &combobox->selectedItem, height, size);
}

Where combobox->style is a struct of type nk_style_combo. From the assignment ctx->style.combo = combobox->style alone, I expected the styles of the buttons in the dropdown to have the style I'd set them to in combobox->style.button (it was a light-blue color, if you're wondering), but in fact the buttons in the dropdown were the same-old default blackish-grey colors.

To get the behavior I was expecting, I had to add this line:

ctx->style.contextual_button = combobox->style.button;

As a user, I think it'd be best if nuklear handled this assignment on its own. If I'm going through the trouble of setting up the nk_button_style object that's in nk_style_combo, then nuklear should be automatically setting the buttons in the combobox dropdown to this style, rather than forcing me as a user to sit and guess which button style is actually affecting the buttons in the combobox dropdown. (Which took me a few minutes since contextual_button doesn't sound like it has anything to do with comboboxes)

dumblob commented 5 years ago

The question seems to be, whether this "background assignment" would work in all cases exactly as the user (programmer) expects. From how I know the styling in Nuklear, I wouldn't rather expect this to be true in all/most cases.

BenjiBoy926 commented 5 years ago

So you mean that sometimes it would happen that I assign ctx->style.contextual_button = (a button style) and it might affect something else besides the buttons in the combobox's dropdown list? Because if so then it sounds like even more of an issue. It means I found a way of setting up the style of the buttons in the combobox's dropdown in a way that is invalid and/or undesirable. If that's true, too, I'd like to know the "proper" way of setting up the styles of the buttons in the combobox's dropdown.

dumblob commented 5 years ago

It seems to boil down to the fact, that styling in Nuklear is still kind of preliminary and to put it bluntly, there are places in the library, where some "theoretically fitting" user style is taken even though it might not necessarily make sense in all cases (which are very hard to analyze) to avoid harcoding of some style.

Another potential issue is, that combo boxes (and any other "overlapping" pieces) are not first class citizens in Nuklear and because styling is designed rather for first class citizens, there will be definitely some edge cases where it won't work as expected.

Feel free to open a pull request and we'll take a look how it (visually) integrates with the existing demos, etc.

BenjiBoy926 commented 5 years ago

When you ask for a pull request, are you suggesting I actually modify the code, or are you talking about adding an example of a well-styled combobox to the wiki? (Maybe both?)

dumblob commented 5 years ago

Code has higher priority, but wiki would be also nice :wink:.

BenjiBoy926 commented 5 years ago

Alrighty! Well, if the pace ever slows here where I work (which isn't very often!) I'll do some digging into the API and see if I can't figure out a good fix. Despite having more than a few kinks that need ironing out, the library is pretty nifty and really well-organized, and it'd be fun to contribute

BenjiBoy926 commented 5 years ago

Oh, also as another question, when you say comboboxes aren't "first class citizens", do you mean that a combobox in itself is only an aggregation of simpler parts, like buttons and contextual panels? Or did you mean something else?

dumblob commented 5 years ago

a combobox in itself is only an aggregation of simpler parts, like buttons and contextual panels?

Yep, that's one thing. Another thing is, that everything which "overlaps" anything else is not first class citizen (architecturally) and as such has side effects :cry:. This part was designed later when it became clear, that Nuklear will not be just a super simple planar UI library, but a full featured, though minimal, UI "microframework".

There is another take on a "minimal though full featured" UI library from the same author called Quarks and a UI layouting "theory demonstration", but there is currently no intention to "market it" as we don't have enough time to maintain the community around etc. But Quarks is a masterpiece of anything UI-related I've seen so far (it even transparently supports "full DPI diversity"!).

BenjiBoy926 commented 5 years ago

Quick question @dumblob , if I want to modify the code in this library and start a pull request, should I modify "nuklear.h" in the root directory or should I modify "src/nuklear.h" in the src folder?

dumblob commented 5 years ago

Modify src/nuklear.h and then follow instructions in src/Readme.md which will automatically generate nuklear.h. Don't forget to change version accordingly.