Skip to content

Commit

Permalink
Merge pull request #580 from yukyduky/disable-widgets
Browse files Browse the repository at this point in the history
Added feature to disable widgets

Check nk_widget_disable_begin() and nk_widget_disable_end(), plus added styles for disable widgets.
  • Loading branch information
riri authored Nov 24, 2023
2 parents 141d3cf + 39e2ee3 commit d052dd6
Show file tree
Hide file tree
Showing 23 changed files with 896 additions and 337 deletions.
2 changes: 1 addition & 1 deletion clib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuklear",
"version": "4.10.7",
"version": "4.11.0",
"repo": "Immediate-Mode-UI/Nuklear",
"description": "A small ANSI C gui toolkit",
"keywords": ["gl", "ui", "toolkit"],
Expand Down
31 changes: 17 additions & 14 deletions demo/common/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ overview(struct nk_context *ctx)

ctx->style.window.header.align = header_align;

static nk_bool disable_widgets = nk_false;

actual_window_flags = window_flags;
if (!(actual_window_flags & NK_WINDOW_TITLE))
actual_window_flags &= ~(NK_WINDOW_MINIMIZABLE|NK_WINDOW_CLOSABLE);
Expand Down Expand Up @@ -129,14 +131,19 @@ overview(struct nk_context *ctx)
nk_checkbox_flags_label(ctx, "No Scrollbar", &window_flags, NK_WINDOW_NO_SCROLLBAR);
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);
}

if (disable_widgets)
nk_widget_disable_begin(ctx);

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

if (nk_tree_push(ctx, NK_TREE_NODE, "Text", NK_MINIMIZED))
{
/* Text Widgets */
Expand Down Expand Up @@ -180,6 +187,7 @@ overview(struct nk_context *ctx)
nk_layout_row_static(ctx, 30, 100, 2);
nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_LEFT, "prev", NK_TEXT_RIGHT);
nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_RIGHT, "next", NK_TEXT_LEFT);

nk_tree_pop(ctx);
}

Expand Down Expand Up @@ -248,24 +256,17 @@ overview(struct nk_context *ctx)

nk_layout_row_static(ctx, 30, 80, 1);
if (inactive) {
struct nk_style_button button;
button = ctx->style.button;
ctx->style.button.normal = nk_style_item_color(nk_rgb(40,40,40));
ctx->style.button.hover = nk_style_item_color(nk_rgb(40,40,40));
ctx->style.button.active = nk_style_item_color(nk_rgb(40,40,40));
ctx->style.button.border_color = nk_rgb(60,60,60);
ctx->style.button.text_background = nk_rgb(60,60,60);
ctx->style.button.text_normal = nk_rgb(60,60,60);
ctx->style.button.text_hover = nk_rgb(60,60,60);
ctx->style.button.text_active = nk_rgb(60,60,60);
nk_button_label(ctx, "button");
ctx->style.button = button;
} else if (nk_button_label(ctx, "button"))
nk_widget_disable_begin(ctx);
}

if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");

nk_widget_disable_end(ctx);

nk_tree_pop(ctx);
}


if (nk_tree_push(ctx, NK_TREE_NODE, "Selectable", NK_MINIMIZED))
{
if (nk_tree_push(ctx, NK_TREE_NODE, "List", NK_MINIMIZED))
Expand Down Expand Up @@ -1289,6 +1290,8 @@ overview(struct nk_context *ctx)
}
nk_tree_pop(ctx);
}
if (disable_widgets)
nk_widget_disable_end(ctx);
}
nk_end(ctx);
return !nk_window_is_closed(ctx, "Overview");
Expand Down
Loading

0 comments on commit d052dd6

Please sign in to comment.