-
Notifications
You must be signed in to change notification settings - Fork 551
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
Conversation
5e74547
to
25cda15
Compare
…into disable-widgets
Added NK_WIDGET_DISABLED_FACTOR, global factor for disabled color
Looks great! Thanks so much. Will let others review 👍 |
That's great. I think it would be cool to add another option to disable all widgets on window. For example add flag like |
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. |
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. |
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. |
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.
There was a problem hiding this 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 :)
src/nuklear_edit.c
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
I will try and fix this ASAP :) |
…into disable-widgets # Conflicts: # clib.json
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@yukyduky Thanks for the functionality and efforts after the review ;-) |
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 :)