Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to disable widgets #580

Merged
merged 12 commits into from
Nov 24, 2023

Conversation

yukyduky
Copy link
Contributor

I've added functions to disable widgets and gray them out. You use it like this:

nk_widget_disable_begin(ctx);
nk_widget(...);
nk_widget(...);
nk_widget(...);
nk_widget_disable_end(ctx);

There's a variable in each style struct in case you want to change the gray out factor per widget type. So far I've only tested it on the widgets in overview.c. Let me know if you have any issues :)

src/nuklear_color.c Outdated Show resolved Hide resolved
src/nuklear_style.c Outdated Show resolved Hide resolved
Added NK_WIDGET_DISABLED_FACTOR, global factor for disabled color
@RobLoach
Copy link
Contributor

Looks great! Thanks so much. Will let others review 👍

@kotvkvante
Copy link

kotvkvante commented Oct 26, 2023

That's great.

I think it would be cool to add another option to disable all widgets on window. For example add flag like NK_WINDOW_DISABLED. We already have NK_WINDOW_NO_INPUT, but it's useless (i think).
I understand that this flag handles different purpose. But I think no one need just disable input without any visual effect of this.

@yukyduky
Copy link
Contributor Author

Neat idea! I personally don't need that atm, but I already have an idea of how to add it so I'll look into it.

@kotvkvante
Copy link

kotvkvante commented Oct 26, 2023

By the way, is it good to change style parameters for every widget and restore them back every time? If I'm using only buttons in my GUI, can I change only button style? I don't know lot about how compilers works (does he enough clever to remove unnecessary assignments??), but.. I go crazy when I think about the speed of programs... If there is no other options to do this or this just how such things works, then ok.. I'm just beginner programmer.

@yukyduky
Copy link
Contributor Author

Is setting the style only for the ones you want faster? Yes. Is it a significant amount? No. I know it looks bad, but it's really not. The alternatives may be slightly faster, but are more cumbersome to deal with for very little gain.

@riri
Copy link
Contributor

riri commented Oct 26, 2023

I'll check this asap

Tree node button background looked out of place when disabled, so I made the background not be affected by being disabled.
Copy link
Contributor

@riri riri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside the C90 compliance change I have asked, I suggest making the disabling functionality more visible in the demo, adding a nk_bool disable_widgets = nk_false variable in the overview, adding a checkbox to change that variable in the Window tree content

            nk_checkbox_flags_label(ctx, "Minimizable", &window_flags, NK_WINDOW_MINIMIZABLE);
            nk_checkbox_flags_label(ctx, "Scale Left", &window_flags, NK_WINDOW_SCALE_LEFT);
            nk_checkbox_label(ctx, "Disable widgets", &disable_widgets);
            nk_tree_pop(ctx);

and globally disabling the Widgets tree content.

        if (nk_tree_push(ctx, NK_TREE_TAB, "Widgets", NK_MINIMIZED))
        {
            enum options {A,B,C};
            static int checkbox;
            static int option;
            if (disable_widgets) nk_widget_disable_begin(ctx);

// ...

            if (nk_tree_push(ctx, NK_TREE_NODE, "Horizontal Rule", NK_MINIMIZED))
            {
                nk_layout_row_dynamic(ctx, 12, 1);
                nk_label(ctx, "Use this to subdivide spaces visually", NK_TEXT_LEFT);
                nk_layout_row_dynamic(ctx, 4, 1);
                nk_rule_horizontal(ctx, nk_white, nk_true);
                nk_layout_row_dynamic(ctx, 75, 1);
                nk_label_wrap(ctx, "Best used in 'Card'-like layouts, with a bigger title font on top. Takes on the size of the previous layout definition. Rounding optional.");
                nk_tree_pop(ctx);
            }
            if (disable_widgets) nk_widget_disable_end(ctx);

            nk_tree_pop(ctx);

I've tried locally and it works great :)

demo

@@ -89,6 +89,9 @@ nk_edit_draw_text(struct nk_command_buffer *out,
float line_offset = 0;
int line_count = 0;

foreground = nk_rgb_factor(foreground, style->color_factor);
background = nk_rgb_factor(background, style->color_factor);

struct nk_text txt;
Copy link
Contributor

@riri riri Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the variable struct nk_text txt up with other variable declarations to be C90 compliant.

@yukyduky
Copy link
Contributor Author

I will try and fix this ASAP :)

@yukyduky
Copy link
Contributor Author

Should be fixed now. I made the widget disabling example be one level further out so that it can also be applied to charts etc.

@yukyduky yukyduky requested a review from riri November 24, 2023 12:29
Copy link
Contributor

@riri riri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@riri riri merged commit d052dd6 into Immediate-Mode-UI:master Nov 24, 2023
@riri
Copy link
Contributor

riri commented Nov 24, 2023

@yukyduky Thanks for the functionality and efforts after the review ;-)

@yukyduky yukyduky deleted the disable-widgets branch November 26, 2023 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants