Immediate-Mode-UI / Nuklear

A single-header ANSI C immediate mode cross-platform GUI library
https://immediate-mode-ui.github.io/Nuklear/
Other
9.33k stars 571 forks source link

hide increase/decrease buttons from nk_property_*() #677

Open efa opened 2 months ago

efa commented 2 months ago

Using: nk_edit_string_zero_terminated() I got a compact widget and node windows: https://github.com/efa/PowerBudget/blob/main/PowerBudgetGUI.png but cannot get to right update for double values.

So I changed to: nk_property_double() now the update of double values work, but the widget has the increase/decrase arrow that waste space. I had to increase the size from 50 to 70 pixel for each value entry, so from 256 to 316 of node windows. I tryed to use "###name" (# autohash, ## skip label, ### skip label and button) and disabling / execute right/left button / code in: nk_do_property() on name[1]=='#', but the space is still reserved and left blank.

I also tryed to comment the:

    /* left decrement button */
    left.h = font->height/2;
...

calculated fill in the same function, but wont work.

Is there a method to hide increase/decrease button to save space?

riri commented 6 days ago

Do you have a repo to show, or at least a code fragment, to see what you use, for both integers and double (that do not work)?

I didn't know about the nk_edit_string_zero_terminated(), but in the demo, there is something similar to:

nk_edit_string(ctx, NK_EDIT_SIMPLE, text, &text_len, 64, nk_filter_float);

Initializing with sprintf() then getting the modified value with dtoa() should work, nk_filter_float() ensuring you get a good real number.

Tell me if I miss something

efa commented 6 days ago

as now in the repo [https://github.com/efa/PowerBudget] I removed the use of nk_edit_string_zero_terminated(), and I have no traces of old not working code. But I'm sure I tryed also nk_edit_string() and the results was the same.

As now I'm not sure what the problem was. If I remember well the problem with nk_edit_string*() was that if user is editing a GUI field with a double inside, and type a letter or a double dot as a mistake, the dtoa convert the number to 0 and so on refresh the user lost the whoole float/double he is editing. Imagine to have 2.5 and want to change to 3.3. Put the cursor after 5, press backspace, and insted of type 3, you press 'e' or '.', the edit field become 0. This because text field, even with nk_filter_float accept two or more dot and even letters before conversion.

This do not happen with nk_property_double() that enforce the inputs of valid numbers. The trouble is that this widget waste more space in the GUI for the arrows, I cannot hide them

riri commented 6 days ago

Yeah I see

I still think changing or customizing nk_property_*() is not the solution, because the property family of widgets are meant to have those features (drag editing, direct typing and increase/decrease with arrows), something you couldn't use in a narrow field.

Maybe something better for casual values editing is needed (doing like nk_property_double() but without integrated label and controls, just the edit field) ?

efa commented 6 days ago

Maybe something better for casual values editing is needed (doing like nk_property_double() but without integrated label and controls, just the edit field) ?

yes to me should be OK, but I haven't found a so widget