From 8016ff334da7120e713287ea3c9d34a7a4305c5e Mon Sep 17 00:00:00 2001 From: Yukyduky Date: Wed, 11 Oct 2023 21:27:52 +0200 Subject: [PATCH 01/10] Added feature to disable widgets --- clib.json | 2 +- demo/common/overview.c | 20 +- nuklear.h | 505 +++++++++++++++++++++++++++---------- src/CHANGELOG | 1 + src/nuklear.h | 31 ++- src/nuklear_button.c | 35 ++- src/nuklear_chart.c | 24 +- src/nuklear_color.c | 10 + src/nuklear_color_picker.c | 2 +- src/nuklear_combo.c | 75 +++--- src/nuklear_contextual.c | 57 +++-- src/nuklear_edit.c | 19 +- src/nuklear_menu.c | 10 +- src/nuklear_progress.c | 18 +- src/nuklear_property.c | 12 +- src/nuklear_selectable.c | 17 +- src/nuklear_slider.c | 19 +- src/nuklear_style.c | 48 ++++ src/nuklear_text.c | 4 +- src/nuklear_toggle.c | 24 +- src/nuklear_widget.c | 99 ++++++++ src/nuklear_window.c | 1 + 22 files changed, 747 insertions(+), 286 deletions(-) diff --git a/clib.json b/clib.json index cf690c789..1cad42bb0 100644 --- a/clib.json +++ b/clib.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.10.6", + "version": "4.11.0", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/demo/common/overview.c b/demo/common/overview.c index 86cb9f210..3c33c8088 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -248,20 +248,14 @@ 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); } diff --git a/nuklear.h b/nuklear.h index 2d754a6b8..0d9b9a2b3 100644 --- a/nuklear.h +++ b/nuklear.h @@ -3076,7 +3076,8 @@ NK_API void nk_list_view_end(struct nk_list_view*); enum nk_widget_layout_states { NK_WIDGET_INVALID, /* The widget cannot be seen and is completely out of view */ NK_WIDGET_VALID, /* The widget is completely inside the window and can be updated and drawn */ - NK_WIDGET_ROM /* The widget is partially visible and cannot be updated */ + NK_WIDGET_ROM, /* The widget is partially visible and cannot be updated */ + NK_WIDGET_DISABLED /* The widget is manually disabled and acts like NK_WIDGET_ROM */ }; enum nk_widget_states { NK_WIDGET_STATE_MODIFIED = NK_FLAG(1), @@ -3099,6 +3100,8 @@ NK_API nk_bool nk_widget_is_hovered(struct nk_context*); NK_API nk_bool nk_widget_is_mouse_clicked(struct nk_context*, enum nk_buttons); NK_API nk_bool nk_widget_has_mouse_click_down(struct nk_context*, enum nk_buttons, nk_bool down); NK_API void nk_spacing(struct nk_context*, int cols); +NK_API void nk_widget_disable_begin(struct nk_context* ctx); +NK_API void nk_widget_disable_end(struct nk_context* ctx); /* ============================================================================= * * TEXT @@ -3669,6 +3672,7 @@ NK_API struct nk_color nk_rgb_f(float r, float g, float b); NK_API struct nk_color nk_rgb_fv(const float *rgb); NK_API struct nk_color nk_rgb_cf(struct nk_colorf c); NK_API struct nk_color nk_rgb_hex(const char *rgb); +NK_API struct nk_color nk_rgb_factor(const struct nk_color col, const float factor); NK_API struct nk_color nk_rgba(int r, int g, int b, int a); NK_API struct nk_color nk_rgba_u32(nk_uint); @@ -4889,6 +4893,8 @@ struct nk_style_item { struct nk_style_text { struct nk_color color; struct nk_vec2 padding; + float color_factor; + float disabled_factor; }; struct nk_style_button { @@ -4911,6 +4917,8 @@ struct nk_style_button { struct nk_vec2 padding; struct nk_vec2 image_padding; struct nk_vec2 touch_padding; + float color_factor; + float disabled_factor; /* optional user callbacks */ nk_handle userdata; @@ -4941,6 +4949,8 @@ struct nk_style_toggle { struct nk_vec2 touch_padding; float spacing; float border; + float color_factor; + float disabled_factor; /* optional user callbacks */ nk_handle userdata; @@ -4976,6 +4986,8 @@ struct nk_style_selectable { struct nk_vec2 padding; struct nk_vec2 touch_padding; struct nk_vec2 image_padding; + float color_factor; + float disabled_factor; /* optional user callbacks */ nk_handle userdata; @@ -5008,6 +5020,8 @@ struct nk_style_slider { struct nk_vec2 padding; struct nk_vec2 spacing; struct nk_vec2 cursor_size; + float color_factor; + float disabled_factor; /* optional buttons */ int show_buttons; @@ -5041,6 +5055,8 @@ struct nk_style_progress { float cursor_border; float cursor_rounding; struct nk_vec2 padding; + float color_factor; + float disabled_factor; /* optional user callbacks */ nk_handle userdata; @@ -5067,6 +5083,8 @@ struct nk_style_scrollbar { float border_cursor; float rounding_cursor; struct nk_vec2 padding; + float color_factor; + float disabled_factor; /* optional buttons */ int show_buttons; @@ -5113,6 +5131,8 @@ struct nk_style_edit { struct nk_vec2 scrollbar_size; struct nk_vec2 padding; float row_padding; + float color_factor; + float disabled_factor; }; struct nk_style_property { @@ -5135,6 +5155,8 @@ struct nk_style_property { float border; float rounding; struct nk_vec2 padding; + float color_factor; + float disabled_factor; struct nk_style_edit edit; struct nk_style_button inc_button; @@ -5157,6 +5179,8 @@ struct nk_style_chart { float border; float rounding; struct nk_vec2 padding; + float color_factor; + float disabled_factor; }; struct nk_style_combo { @@ -5188,6 +5212,8 @@ struct nk_style_combo { struct nk_vec2 content_padding; struct nk_vec2 button_padding; struct nk_vec2 spacing; + float color_factor; + float disabled_factor; }; struct nk_style_tab { @@ -5210,6 +5236,8 @@ struct nk_style_tab { float indent; struct nk_vec2 padding; struct nk_vec2 spacing; + float color_factor; + float disabled_factor; }; enum nk_style_header_align { @@ -5492,6 +5520,7 @@ struct nk_window { struct nk_popup_state popup; struct nk_edit_state edit; unsigned int scrolled; + nk_bool widgets_disabled; struct nk_table *tables; unsigned int table_count; @@ -7575,6 +7604,16 @@ nk_parse_hex(const char *p, int length) return i; } NK_API struct nk_color +nk_rgb_factor(const struct nk_color col, const float factor) +{ + struct nk_color ret; + ret.r = col.r * factor; + ret.g = col.g * factor; + ret.b = col.b * factor; + ret.a = col.a; + return ret; +} +NK_API struct nk_color nk_rgba(int r, int g, int b, int a) { struct nk_color ret; @@ -18212,6 +18251,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) text = &style->text; text->color = table[NK_COLOR_TEXT]; text->padding = nk_vec2(0,0); + text->color_factor = 1.0f; + text->disabled_factor = 0.5f; /* default button */ button = &style->button; @@ -18231,6 +18272,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 4.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -18251,6 +18294,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -18271,6 +18316,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 1.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -18292,6 +18339,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) toggle->border_color = nk_rgba(0,0,0,0); toggle->border = 0.0f; toggle->spacing = 4; + toggle->color_factor = 1.0f; + toggle->disabled_factor = 0.5f; /* option toggle */ toggle = &style->option; @@ -18311,6 +18360,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) toggle->border_color = nk_rgba(0,0,0,0); toggle->border = 0.0f; toggle->spacing = 4; + toggle->color_factor = 1.0f; + toggle->disabled_factor = 0.5f; /* selectable */ select = &style->selectable; @@ -18332,6 +18383,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) select->touch_padding = nk_vec2(0,0); select->userdata = nk_handle_ptr(0); select->rounding = 0.0f; + select->color_factor = 1.0f; + select->disabled_factor = 0.5f; select->draw_begin = 0; select->draw_end = 0; @@ -18357,6 +18410,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) slider->show_buttons = nk_false; slider->bar_height = 8; slider->rounding = 0; + slider->color_factor = 1.0f; + slider->disabled_factor = 0.5f; slider->draw_begin = 0; slider->draw_end = 0; @@ -18376,6 +18431,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->slider.dec_button = style->slider.inc_button; @@ -18397,6 +18454,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) prog->border = 0; prog->cursor_rounding = 0; prog->cursor_border = 0; + prog->color_factor = 1.0f; + prog->disabled_factor = 0.5f; prog->draw_begin = 0; prog->draw_end = 0; @@ -18420,6 +18479,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) scroll->rounding = 0; scroll->border_cursor = 0; scroll->rounding_cursor = 0; + scroll->color_factor = 1.0f; + scroll->disabled_factor = 0.5f; scroll->draw_begin = 0; scroll->draw_end = 0; style->scrollv = style->scrollh; @@ -18440,6 +18501,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->scrollh.dec_button = style->scrollh.inc_button; @@ -18471,6 +18534,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) edit->cursor_size = 4; edit->border = 1; edit->rounding = 0; + edit->color_factor = 1.0f; + edit->disabled_factor = 0.5f; /* property */ property = &style->property; @@ -18490,6 +18555,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) property->rounding = 10; property->draw_begin = 0; property->draw_end = 0; + property->color_factor = 1.0f; + property->disabled_factor = 0.5f; /* property buttons */ button = &style->property.dec_button; @@ -18508,6 +18575,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->property.inc_button = style->property.dec_button; @@ -18534,6 +18603,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) edit->cursor_size = 8; edit->border = 0; edit->rounding = 0; + edit->color_factor = 1.0f; + edit->disabled_factor = 0.5f; /* chart */ chart = &style->chart; @@ -18545,6 +18616,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) chart->padding = nk_vec2(4,4); chart->border = 0; chart->rounding = 0; + chart->color_factor = 1.0f; + chart->disabled_factor = 0.5f; /* combo */ combo = &style->combo; @@ -18563,6 +18636,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) combo->spacing = nk_vec2(4,0); combo->border = 1; combo->rounding = 0; + combo->color_factor = 1.0f; + combo->disabled_factor = 0.5f; /* combo button */ button = &style->combo.button; @@ -18581,6 +18656,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -18596,6 +18673,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) tab->indent = 10.0f; tab->border = 1; tab->rounding = 0; + tab->color_factor = 1.0f; + tab->disabled_factor = 0.5f; /* tab button */ button = &style->tab.tab_minimize_button; @@ -18614,6 +18693,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->tab.tab_maximize_button =*button; @@ -18635,6 +18716,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->tab.node_maximize_button =*button; @@ -18672,6 +18755,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -18692,6 +18777,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -20241,6 +20328,7 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, NK_MEMCPY(win->name_string, name, name_length); win->name_string[name_length] = 0; win->popup.win = 0; + win->widgets_disabled = false; if (!ctx->active) ctx->active = win; } else { @@ -21010,6 +21098,7 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size, struct nk_window *win; struct nk_window *popup; struct nk_rect body; + struct nk_input* in; NK_STORAGE const struct nk_rect null_rect = {-1,-1,0,0}; int is_clicked = 0; @@ -21030,35 +21119,39 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size, /* check if currently active contextual is active */ popup = win->popup.win; is_open = (popup && win->popup.type == NK_PANEL_CONTEXTUAL); - is_clicked = nk_input_mouse_clicked(&ctx->input, NK_BUTTON_RIGHT, trigger_bounds); - if (win->popup.active_con && win->popup.con_count != win->popup.active_con) - return 0; - if (!is_open && win->popup.active_con) - win->popup.active_con = 0; - if ((!is_open && !is_clicked)) - return 0; + in = win->widgets_disabled ? 0 : &ctx->input; + if (in) { + is_clicked = nk_input_mouse_clicked(in, NK_BUTTON_RIGHT, trigger_bounds); + if (win->popup.active_con && win->popup.con_count != win->popup.active_con) + return 0; + if (!is_open && win->popup.active_con) + win->popup.active_con = 0; + if ((!is_open && !is_clicked)) + return 0; - /* calculate contextual position on click */ - win->popup.active_con = win->popup.con_count; - if (is_clicked) { - body.x = ctx->input.mouse.pos.x; - body.y = ctx->input.mouse.pos.y; - } else { - body.x = popup->bounds.x; - body.y = popup->bounds.y; - } - body.w = size.x; - body.h = size.y; + /* calculate contextual position on click */ + win->popup.active_con = win->popup.con_count; + if (is_clicked) { + body.x = in->mouse.pos.x; + body.y = in->mouse.pos.y; + } else { + body.x = popup->bounds.x; + body.y = popup->bounds.y; + } + + body.w = size.x; + body.h = size.y; - /* start nonblocking contextual popup */ - ret = nk_nonblock_begin(ctx, flags|NK_WINDOW_NO_SCROLLBAR, body, + /* start nonblocking contextual popup */ + ret = nk_nonblock_begin(ctx, flags | NK_WINDOW_NO_SCROLLBAR, body, null_rect, NK_PANEL_CONTEXTUAL); - if (ret) win->popup.type = NK_PANEL_CONTEXTUAL; - else { - win->popup.active_con = 0; - win->popup.type = NK_PANEL_NONE; - if (win->popup.win) - win->popup.win->flags = 0; + if (ret) win->popup.type = NK_PANEL_CONTEXTUAL; + else { + win->popup.active_con = 0; + win->popup.type = NK_PANEL_NONE; + if (win->popup.win) + win->popup.win->flags = 0; + } } return ret; } @@ -21347,7 +21440,7 @@ nk_menu_begin_text(struct nk_context *ctx, const char *title, int len, win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, header, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) is_clicked = nk_true; @@ -21377,7 +21470,7 @@ nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_image(&ctx->last_widget_state, &win->buffer, header, img, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in)) is_clicked = nk_true; @@ -21402,7 +21495,7 @@ nk_menu_begin_symbol(struct nk_context *ctx, const char *id, win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, header, sym, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) is_clicked = nk_true; @@ -21427,7 +21520,7 @@ nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len, win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, header, img, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, ctx->style.font, in)) @@ -21460,7 +21553,7 @@ nk_menu_begin_symbol_text(struct nk_context *ctx, const char *title, int len, state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, header, sym, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, ctx->style.font, in)) is_clicked = nk_true; @@ -23132,6 +23225,8 @@ nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) return NK_WIDGET_INVALID; + if (win->widgets_disabled) + return NK_WIDGET_DISABLED; if (!NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, v.x, v.y, v.w, v.h)) return NK_WIDGET_ROM; return NK_WIDGET_VALID; @@ -23184,7 +23279,104 @@ nk_spacing(struct nk_context *ctx, int cols) nk_panel_alloc_space(&none, ctx); } layout->row.index = index; } +NK_API void +nk_widget_disable_begin(struct nk_context* ctx) +{ + struct nk_window* win; + struct nk_style* style; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + + if (!ctx || !ctx->current) + return; + + win = ctx->current; + style = &ctx->style; + + win->widgets_disabled = nk_true; + + style->button.color_factor = style->button.disabled_factor; + style->chart.color_factor = style->chart.disabled_factor; + style->checkbox.color_factor = style->checkbox.disabled_factor; + style->combo.color_factor = style->combo.disabled_factor; + style->combo.button.color_factor = style->combo.button.disabled_factor; + style->contextual_button.color_factor = style->contextual_button.disabled_factor; + style->edit.color_factor = style->edit.disabled_factor; + style->edit.scrollbar.color_factor = style->edit.scrollbar.disabled_factor; + style->menu_button.color_factor = style->menu_button.disabled_factor; + style->option.color_factor = style->option.disabled_factor; + style->progress.color_factor = style->progress.disabled_factor; + style->property.color_factor = style->property.disabled_factor; + style->property.inc_button.color_factor = style->property.inc_button.disabled_factor; + style->property.dec_button.color_factor = style->property.dec_button.disabled_factor; + style->property.edit.color_factor = style->property.edit.disabled_factor; + style->scrollh.color_factor = style->scrollh.disabled_factor; + style->scrollh.inc_button.color_factor = style->scrollh.inc_button.disabled_factor; + style->scrollh.dec_button.color_factor = style->scrollh.dec_button.disabled_factor; + style->scrollv.color_factor = style->scrollv.disabled_factor; + style->scrollv.inc_button.color_factor = style->scrollv.inc_button.disabled_factor; + style->scrollv.dec_button.color_factor = style->scrollv.dec_button.disabled_factor; + style->selectable.color_factor = style->selectable.disabled_factor; + style->slider.color_factor = style->slider.disabled_factor; + style->slider.inc_button.color_factor = style->slider.inc_button.disabled_factor; + style->slider.dec_button.color_factor = style->slider.dec_button.disabled_factor; + style->tab.color_factor = style->tab.disabled_factor; + style->tab.node_maximize_button.color_factor = style->tab.node_maximize_button.disabled_factor; + style->tab.node_minimize_button.color_factor = style->tab.node_minimize_button.disabled_factor; + style->tab.tab_maximize_button.color_factor = style->tab.tab_maximize_button.disabled_factor; + style->tab.tab_minimize_button.color_factor = style->tab.tab_minimize_button.disabled_factor; + style->text.color_factor = style->text.disabled_factor; +} +NK_API void +nk_widget_disable_end(struct nk_context* ctx) +{ + struct nk_window* win; + struct nk_style* style; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + + if (!ctx || !ctx->current) + return; + + win = ctx->current; + style = &ctx->style; + win->widgets_disabled = nk_false; + + style->button.color_factor = 1.0f; + style->chart.color_factor = 1.0f; + style->checkbox.color_factor = 1.0f; + style->combo.color_factor = 1.0f; + style->combo.button.color_factor = 1.0f; + style->contextual_button.color_factor = 1.0f; + style->edit.color_factor = 1.0f; + style->edit.scrollbar.color_factor = 1.0f; + style->menu_button.color_factor = 1.0f; + style->option.color_factor = 1.0f; + style->progress.color_factor = 1.0f; + style->property.color_factor = 1.0f; + style->property.inc_button.color_factor = 1.0f; + style->property.dec_button.color_factor = 1.0f; + style->property.edit.color_factor = 1.0f; + style->scrollh.color_factor = 1.0f; + style->scrollh.inc_button.color_factor = 1.0f; + style->scrollh.dec_button.color_factor = 1.0f; + style->scrollv.color_factor = 1.0f; + style->scrollv.inc_button.color_factor = 1.0f; + style->scrollv.dec_button.color_factor = 1.0f; + style->selectable.color_factor = 1.0f; + style->slider.color_factor = 1.0f; + style->slider.inc_button.color_factor = 1.0f; + style->slider.dec_button.color_factor = 1.0f; + style->tab.color_factor = 1.0f; + style->tab.node_maximize_button.color_factor = 1.0f; + style->tab.node_minimize_button.color_factor = 1.0f; + style->tab.tab_maximize_button.color_factor = 1.0f; + style->tab.tab_minimize_button.color_factor = 1.0f; + style->text.color_factor = 1.0f; +} @@ -23302,7 +23494,7 @@ nk_text_colored(struct nk_context *ctx, const char *str, int len, text.padding.x = item_padding.x; text.padding.y = item_padding.y; text.background = style->window.background; - text.text = color; + text.text = nk_rgb_factor(color, style->text.color_factor); nk_widget_text(&win->buffer, bounds, str, len, &text, alignment, style->font); } NK_API void @@ -23329,7 +23521,7 @@ nk_text_wrap_colored(struct nk_context *ctx, const char *str, text.padding.x = item_padding.x; text.padding.y = item_padding.y; text.background = style->window.background; - text.text = color; + text.text = nk_rgb_factor(color, style->text.color_factor); nk_widget_text_wrap(&win->buffer, bounds, str, len, &text, style->font); } #ifdef NK_INCLUDE_STANDARD_VARARGS @@ -23826,16 +24018,16 @@ nk_draw_button(struct nk_command_buffer *out, background = &style->active; else background = &style->normal; - switch(background->type) { + switch (background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_rgb_factor(nk_white, style->color_factor), style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *bounds, style->rounding, background->data.color); - nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; } return background; @@ -23885,6 +24077,8 @@ nk_draw_button_text(struct nk_command_buffer *out, text.text = style->text_active; else text.text = style->text_normal; + text.text = nk_rgb_factor(text.text, style->color_factor); + text.padding = nk_vec2(0,0); nk_widget_text(out, *content, txt, len, &text, text_alignment, font); } @@ -23932,6 +24126,8 @@ nk_draw_button_symbol(struct nk_command_buffer *out, else if (state & NK_WIDGET_STATE_ACTIVED) sym = style->text_active; else sym = style->text_normal; + + sym = nk_rgb_factor(sym, style->color_factor); nk_draw_symbol(out, type, *content, bg, sym, 1, font); } NK_LIB nk_bool @@ -23963,7 +24159,7 @@ nk_draw_button_image(struct nk_command_buffer *out, nk_flags state, const struct nk_style_button *style, const struct nk_image *img) { nk_draw_button(out, bounds, state, style); - nk_draw_image(out, *content, img, nk_white); + nk_draw_image(out, *content, img, nk_rgb_factor(nk_white, style->color_factor)); } NK_LIB nk_bool nk_do_button_image(nk_flags *state, @@ -24020,6 +24216,8 @@ nk_draw_button_text_symbol(struct nk_command_buffer *out, text.text = style->text_normal; } + sym = nk_rgb_factor(sym, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor); text.padding = nk_vec2(0,0); nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font); nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); @@ -24077,9 +24275,10 @@ nk_draw_button_text_image(struct nk_command_buffer *out, text.text = style->text_active; else text.text = style->text_normal; - text.padding = nk_vec2(0,0); + text.text = nk_rgb_factor(text.text, style->color_factor); + text.padding = nk_vec2(0, 0); nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); - nk_draw_image(out, *image, img, nk_white); + nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor)); } NK_LIB nk_bool nk_do_button_text_image(nk_flags *state, @@ -24184,7 +24383,7 @@ nk_button_text_styled(struct nk_context *ctx, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, title, len, style->text_alignment, ctx->button_behavior, style, in, ctx->style.font); @@ -24229,7 +24428,7 @@ nk_button_color(struct nk_context *ctx, struct nk_color color) state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; button = ctx->style.button; button.normal = nk_style_item_color(color); @@ -24261,7 +24460,7 @@ nk_button_symbol_styled(struct nk_context *ctx, layout = win->layout; state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds, symbol, ctx->button_behavior, style, in, ctx->style.font); } @@ -24294,7 +24493,7 @@ nk_button_image_styled(struct nk_context *ctx, const struct nk_style_button *sty state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_image(&ctx->last_widget_state, &win->buffer, bounds, img, ctx->button_behavior, style, in); } @@ -24328,7 +24527,7 @@ nk_button_symbol_text_styled(struct nk_context *ctx, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds, symbol, text, len, align, ctx->button_behavior, style, ctx->style.font, in); @@ -24375,7 +24574,7 @@ nk_button_image_text_styled(struct nk_context *ctx, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, bounds, img, text, len, align, ctx->button_behavior, style, ctx->style.font, in); @@ -24448,14 +24647,16 @@ nk_draw_checkbox(struct nk_command_buffer *out, text.text = style->text_normal; } + text.text = nk_rgb_factor(text.text, style->color_factor); + /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { - nk_fill_rect(out, *selector, 0, style->border_color); - nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, background->data.color); - } else nk_draw_image(out, *selector, &background->data.image, nk_white); + nk_fill_rect(out, *selector, 0, nk_rgb_factor(style->border_color, style->color_factor)); + nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, nk_rgb_factor(background->data.color, style->color_factor)); + } else nk_draw_image(out, *selector, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); if (active) { if (cursor->type == NK_STYLE_ITEM_IMAGE) - nk_draw_image(out, *cursors, &cursor->data.image, nk_white); + nk_draw_image(out, *cursors, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); else nk_fill_rect(out, *cursors, 0, cursor->data.color); } @@ -24490,14 +24691,16 @@ nk_draw_option(struct nk_command_buffer *out, text.text = style->text_normal; } + text.text = nk_rgb_factor(text.text, style->color_factor); + /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { - nk_fill_circle(out, *selector, style->border_color); - nk_fill_circle(out, nk_shrink_rect(*selector, style->border), background->data.color); - } else nk_draw_image(out, *selector, &background->data.image, nk_white); + nk_fill_circle(out, *selector, nk_rgb_factor(style->border_color, style->color_factor)); + nk_fill_circle(out, nk_shrink_rect(*selector, style->border), nk_rgb_factor(background->data.color, style->color_factor)); + } else nk_draw_image(out, *selector, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); if (active) { if (cursor->type == NK_STYLE_ITEM_IMAGE) - nk_draw_image(out, *cursors, &cursor->data.image, nk_white); + nk_draw_image(out, *cursors, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); else nk_fill_circle(out, *cursors, cursor->data.color); } @@ -24596,7 +24799,7 @@ nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active) state = nk_widget(&bounds, ctx); if (!state) return active; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active, text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font); return active; @@ -24691,7 +24894,7 @@ nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_act state = nk_widget(&bounds, ctx); if (!state) return (int)state; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &is_active, text, len, NK_TOGGLE_OPTION, &style->option, in, style->font); return is_active; @@ -24763,23 +24966,26 @@ nk_draw_selectable(struct nk_command_buffer *out, text.text = style->text_normal_active; } } + + text.text = nk_rgb_factor(text.text, style->color_factor); + /* draw selectable background and text */ switch (background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(out, *bounds, style->rounding, background->data.color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); break; } if (icon) { - if (img) nk_draw_image(out, *icon, img, nk_white); + if (img) nk_draw_image(out, *icon, img, nk_rgb_factor(nk_white, style->color_factor)); else nk_draw_symbol(out, sym, *icon, text.background, text.text, 1, font); } nk_widget_text(out, *bounds, string, len, &text, align, font); @@ -24940,7 +25146,7 @@ nk_selectable_text(struct nk_context *ctx, const char *str, int len, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_selectable(&ctx->last_widget_state, &win->buffer, bounds, str, len, align, value, &style->selectable, in, style->font); } @@ -24969,7 +25175,7 @@ nk_selectable_image_text(struct nk_context *ctx, struct nk_image img, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_selectable_image(&ctx->last_widget_state, &win->buffer, bounds, str, len, align, value, &img, &style->selectable, in, style->font); } @@ -24998,7 +25204,7 @@ nk_selectable_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_selectable_symbol(&ctx->last_widget_state, &win->buffer, bounds, str, len, align, value, sym, &style->selectable, in, style->font); } @@ -25130,6 +25336,7 @@ nk_draw_slider(struct nk_command_buffer *out, nk_flags state, bar_color = style->bar_normal; cursor = &style->cursor_normal; } + /* calculate slider background bar */ bar.x = bounds->x; bar.y = (visual_cursor->y + visual_cursor->h/2) - bounds->h/12; @@ -25145,26 +25352,26 @@ nk_draw_slider(struct nk_command_buffer *out, nk_flags state, /* draw background */ switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *bounds, style->rounding, background->data.color); - nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; } /* draw slider bar */ - nk_fill_rect(out, bar, style->rounding, bar_color); - nk_fill_rect(out, fill, style->rounding, style->bar_filled); + nk_fill_rect(out, bar, style->rounding, nk_rgb_factor(bar_color, style->color_factor)); + nk_fill_rect(out, fill, style->rounding, nk_rgb_factor(style->bar_filled, style->color_factor)); /* draw cursor */ if (cursor->type == NK_STYLE_ITEM_IMAGE) - nk_draw_image(out, *visual_cursor, &cursor->data.image, nk_white); + nk_draw_image(out, *visual_cursor, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); else - nk_fill_circle(out, *visual_cursor, cursor->data.color); + nk_fill_circle(out, *visual_cursor, nk_rgb_factor(cursor->data.color, style->color_factor)); } NK_LIB float nk_do_slider(nk_flags *state, @@ -25282,7 +25489,7 @@ nk_slider_float(struct nk_context *ctx, float min_value, float *value, float max state = nk_widget(&bounds, ctx); if (!state) return ret; - in = (/*state == NK_WIDGET_ROM || */ layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (/*state == NK_WIDGET_ROM || */ state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; old_value = *value; *value = nk_do_slider(&ctx->last_widget_state, &win->buffer, bounds, min_value, @@ -25376,28 +25583,28 @@ nk_draw_progress(struct nk_command_buffer *out, nk_flags state, /* draw background */ switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *bounds, style->rounding, background->data.color); - nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; } /* draw cursor */ switch(cursor->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *scursor, &cursor->data.image, nk_white); + nk_draw_image(out, *scursor, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *scursor, &cursor->data.slice, nk_white); + nk_draw_nine_slice(out, *scursor, &cursor->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *scursor, style->rounding, cursor->data.color); - nk_stroke_rect(out, *scursor, style->rounding, style->border, style->border_color); + nk_fill_rect(out, *scursor, style->rounding, nk_rgb_factor(cursor->data.color, style->color_factor)); + nk_stroke_rect(out, *scursor, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; } } @@ -25457,7 +25664,7 @@ nk_progress(struct nk_context *ctx, nk_size *cur, nk_size max, nk_bool is_modify state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; old_value = *cur; *cur = nk_do_progress(&ctx->last_widget_state, &win->buffer, bounds, *cur, max, is_modifyable, &style->progress, in); @@ -26903,6 +27110,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; txt.padding = nk_vec2(0,0); txt.background = background; @@ -27145,14 +27355,14 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, /* draw background frame */ switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, bounds, &background->data.image, nk_white); + nk_draw_image(out, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, bounds, style->rounding, background->data.color); - nk_stroke_rect(out, bounds, style->rounding, style->border, style->border_color); + nk_fill_rect(out, bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; }} @@ -27361,6 +27571,8 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, else background_color = background->data.color; + cursor_color = nk_rgb_factor(cursor_color, style->color_factor); + cursor_text_color = nk_rgb_factor(cursor_text_color, style->color_factor); if (edit->select_start == edit->select_end) { /* no selection so just draw the complete text */ @@ -27468,6 +27680,10 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, background_color = nk_rgba(0,0,0,0); else background_color = background->data.color; + + background_color = nk_rgb_factor(background_color, style->color_factor); + text_color = nk_rgb_factor(text_color, style->color_factor); + nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, area.y - edit->scrollbar.y, 0, begin, l, row_height, font, background_color, text_color, nk_false); @@ -27587,6 +27803,8 @@ nk_edit_buffer(struct nk_context *ctx, nk_flags flags, style = &ctx->style; state = nk_widget(&bounds, ctx); if (!state) return state; + else if (state == NK_WIDGET_DISABLED) + flags |= NK_EDIT_READ_ONLY; in = (win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; /* check if edit is currently hot item */ @@ -27720,20 +27938,22 @@ nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property * text.text = style->label_normal; } + text.text = nk_rgb_factor(text.text, style->color_factor); + /* draw background */ switch(background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(out, *bounds, style->rounding, background->data.color); - nk_stroke_rect(out, *bounds, style->rounding, style->border, background->data.color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(background->data.color, style->color_factor)); break; } @@ -28018,7 +28238,7 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant old_state = *state; ctx->text_edit.clip = ctx->clip; in = ((s == NK_WIDGET_ROM && !win->property.active) || - layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED) ? 0 : &ctx->input; nk_do_property(&ctx->last_widget_state, &win->buffer, bounds, name, variant, inc_per_pixel, buffer, len, state, cursor, select_begin, select_end, &style->property, filter, in, style->font, &ctx->text_edit, @@ -28187,7 +28407,7 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, {struct nk_chart_slot *slot = &chart->slots[chart->slot++]; slot->type = type; slot->count = count; - slot->color = color; + slot->color = nk_rgb_factor(color, style->color_factor); slot->highlight = highlight; slot->min = NK_MIN(min_value, max_value); slot->max = NK_MAX(min_value, max_value); @@ -28198,15 +28418,15 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(&win->buffer, bounds, &background->data.image, nk_white); + nk_draw_image(&win->buffer, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(&win->buffer, bounds, &background->data.slice, nk_white); + nk_draw_image(&win->buffer, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(&win->buffer, bounds, style->rounding, style->border_color); + nk_fill_rect(&win->buffer, bounds, style->rounding, nk_rgb_factor(style->border_color, style->color_factor)); nk_fill_rect(&win->buffer, nk_shrink_rect(bounds, style->border), - style->rounding, style->background.data.color); + style->rounding, nk_rgb_factor(style->background.data.color, style->color_factor)); break; } return 1; @@ -28223,6 +28443,8 @@ nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type, struct nk_color color, struct nk_color highlight, int count, float min_value, float max_value) { + const struct nk_style_chart* style; + NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); @@ -28230,12 +28452,14 @@ nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type, if (!ctx || !ctx->current || !ctx->current->layout) return; if (ctx->current->layout->chart.slot >= NK_CHART_MAX_SLOT) return; + style = &ctx->style.chart; + /* add another slot into the graph */ {struct nk_chart *chart = &ctx->current->layout->chart; struct nk_chart_slot *slot = &chart->slots[chart->slot++]; slot->type = type; slot->count = count; - slot->color = color; + slot->color = nk_rgb_factor(color, style->color_factor); slot->highlight = highlight; slot->min = NK_MIN(min_value, max_value); slot->max = NK_MAX(min_value, max_value); @@ -28253,7 +28477,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, struct nk_chart *g, float value, int slot) { struct nk_panel *layout = win->layout; - const struct nk_input *i = &ctx->input; + const struct nk_input *i = ctx->current->widgets_disabled ? 0 : &ctx->input; struct nk_command_buffer *out = &win->buffer; nk_flags ret = 0; @@ -28279,7 +28503,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, bounds.w = bounds.h = 4; color = g->slots[slot].color; - if (!(layout->flags & NK_WINDOW_ROM) && + if (!(layout->flags & NK_WINDOW_ROM) && i && NK_INBOX(i->mouse.pos.x,i->mouse.pos.y, g->slots[slot].last.x-3, g->slots[slot].last.y-3, 6, 6)){ ret = nk_input_is_mouse_hovering_rect(i, bounds) ? NK_CHART_HOVERING : 0; ret |= (i->mouse.buttons[NK_BUTTON_LEFT].down && @@ -28323,7 +28547,7 @@ nk_chart_push_column(const struct nk_context *ctx, struct nk_window *win, struct nk_chart *chart, float value, int slot) { struct nk_command_buffer *out = &win->buffer; - const struct nk_input *in = &ctx->input; + const struct nk_input *in = ctx->current->widgets_disabled ? 0 : &ctx->input; struct nk_panel *layout = win->layout; float ratio; @@ -28353,7 +28577,7 @@ nk_chart_push_column(const struct nk_context *ctx, struct nk_window *win, item.x = item.x + ((float)chart->slots[slot].index); /* user chart bar selection */ - if (!(layout->flags & NK_WINDOW_ROM) && + if (!(layout->flags & NK_WINDOW_ROM) && in && NK_INBOX(in->mouse.pos.x,in->mouse.pos.y,item.x,item.y,item.w,item.h)) { ret = NK_CHART_HOVERING; ret |= (!in->mouse.buttons[NK_BUTTON_LEFT].down && @@ -28652,7 +28876,7 @@ nk_color_pick(struct nk_context * ctx, struct nk_colorf *color, layout = win->layout; state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_color_picker(&ctx->last_widget_state, &win->buffer, color, fmt, bounds, nk_vec2(0,0), in, config->font); } @@ -28734,7 +28958,7 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, if (s == NK_WIDGET_INVALID) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -28750,19 +28974,21 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, text.text = style->combo.label_normal; } + text.text = nk_rgb_factor(text.text, style->combo.color_factor); + switch(background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -28842,7 +29068,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve if (s == NK_WIDGET_INVALID) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -28855,14 +29081,14 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -28900,7 +29126,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x; else bounds.w = header.w - 4 * style->combo.content_padding.x; - nk_fill_rect(&win->buffer, bounds, 0, color); + nk_fill_rect(&win->buffer, bounds, 0, nk_rgb_factor(color, style->combo.color_factor)); /* draw open/close button */ if (draw_button_symbol) @@ -28935,7 +29161,7 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct if (s == NK_WIDGET_INVALID) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -28951,19 +29177,21 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct symbol_color = style->combo.symbol_hover; } + symbol_color = nk_rgb_factor(symbol_color, style->combo.color_factor); + switch(background->type) { case NK_STYLE_ITEM_IMAGE: sym_background = nk_rgba(0, 0, 0, 0); - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: sym_background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: sym_background = background->data.color; - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -29029,7 +29257,7 @@ nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len s = nk_widget(&header, ctx); if (!s) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -29048,19 +29276,22 @@ nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len text.text = style->combo.label_normal; } + text.text = nk_rgb_factor(text.text, style->combo.color_factor); + symbol_color = nk_rgb_factor(symbol_color, style->combo.color_factor); + switch(background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -29131,7 +29362,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 if (s == NK_WIDGET_INVALID) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -29144,14 +29375,14 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 switch (background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -29189,7 +29420,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 bounds.w = (button.x - style->combo.content_padding.y) - bounds.x; else bounds.w = header.w - 2 * style->combo.content_padding.x; - nk_draw_image(&win->buffer, bounds, &img, nk_white); + nk_draw_image(&win->buffer, bounds, &img, nk_rgb_factor(nk_white, style->combo.color_factor)); /* draw open/close button */ if (draw_button_symbol) @@ -29223,7 +29454,7 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, s = nk_widget(&header, ctx); if (!s) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -29239,19 +29470,21 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, text.text = style->combo.label_normal; } + text.text = nk_rgb_factor(text.text, style->combo.color_factor); + switch(background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -29290,7 +29523,7 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, image.y = header.y + style->combo.content_padding.y; image.h = header.h - 2 * style->combo.content_padding.y; image.w = image.h; - nk_draw_image(&win->buffer, image, &img, nk_white); + nk_draw_image(&win->buffer, image, &img, nk_rgb_factor(nk_white, style->combo.color_factor)); /* draw label */ text.padding = nk_vec2(0,0); diff --git a/src/CHANGELOG b/src/CHANGELOG index 4bcdfdb94..7407f3adb 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() /// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly /// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 diff --git a/src/nuklear.h b/src/nuklear.h index 5111d9bee..4d8038a1e 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -2854,7 +2854,8 @@ NK_API void nk_list_view_end(struct nk_list_view*); enum nk_widget_layout_states { NK_WIDGET_INVALID, /* The widget cannot be seen and is completely out of view */ NK_WIDGET_VALID, /* The widget is completely inside the window and can be updated and drawn */ - NK_WIDGET_ROM /* The widget is partially visible and cannot be updated */ + NK_WIDGET_ROM, /* The widget is partially visible and cannot be updated */ + NK_WIDGET_DISABLED /* The widget is manually disabled and acts like NK_WIDGET_ROM */ }; enum nk_widget_states { NK_WIDGET_STATE_MODIFIED = NK_FLAG(1), @@ -2877,6 +2878,8 @@ NK_API nk_bool nk_widget_is_hovered(struct nk_context*); NK_API nk_bool nk_widget_is_mouse_clicked(struct nk_context*, enum nk_buttons); NK_API nk_bool nk_widget_has_mouse_click_down(struct nk_context*, enum nk_buttons, nk_bool down); NK_API void nk_spacing(struct nk_context*, int cols); +NK_API void nk_widget_disable_begin(struct nk_context* ctx); +NK_API void nk_widget_disable_end(struct nk_context* ctx); /* ============================================================================= * * TEXT @@ -3447,6 +3450,7 @@ NK_API struct nk_color nk_rgb_f(float r, float g, float b); NK_API struct nk_color nk_rgb_fv(const float *rgb); NK_API struct nk_color nk_rgb_cf(struct nk_colorf c); NK_API struct nk_color nk_rgb_hex(const char *rgb); +NK_API struct nk_color nk_rgb_factor(const struct nk_color col, const float factor); NK_API struct nk_color nk_rgba(int r, int g, int b, int a); NK_API struct nk_color nk_rgba_u32(nk_uint); @@ -4667,6 +4671,8 @@ struct nk_style_item { struct nk_style_text { struct nk_color color; struct nk_vec2 padding; + float color_factor; + float disabled_factor; }; struct nk_style_button { @@ -4689,6 +4695,8 @@ struct nk_style_button { struct nk_vec2 padding; struct nk_vec2 image_padding; struct nk_vec2 touch_padding; + float color_factor; + float disabled_factor; /* optional user callbacks */ nk_handle userdata; @@ -4719,6 +4727,8 @@ struct nk_style_toggle { struct nk_vec2 touch_padding; float spacing; float border; + float color_factor; + float disabled_factor; /* optional user callbacks */ nk_handle userdata; @@ -4754,6 +4764,8 @@ struct nk_style_selectable { struct nk_vec2 padding; struct nk_vec2 touch_padding; struct nk_vec2 image_padding; + float color_factor; + float disabled_factor; /* optional user callbacks */ nk_handle userdata; @@ -4786,6 +4798,8 @@ struct nk_style_slider { struct nk_vec2 padding; struct nk_vec2 spacing; struct nk_vec2 cursor_size; + float color_factor; + float disabled_factor; /* optional buttons */ int show_buttons; @@ -4819,6 +4833,8 @@ struct nk_style_progress { float cursor_border; float cursor_rounding; struct nk_vec2 padding; + float color_factor; + float disabled_factor; /* optional user callbacks */ nk_handle userdata; @@ -4845,6 +4861,8 @@ struct nk_style_scrollbar { float border_cursor; float rounding_cursor; struct nk_vec2 padding; + float color_factor; + float disabled_factor; /* optional buttons */ int show_buttons; @@ -4891,6 +4909,8 @@ struct nk_style_edit { struct nk_vec2 scrollbar_size; struct nk_vec2 padding; float row_padding; + float color_factor; + float disabled_factor; }; struct nk_style_property { @@ -4913,6 +4933,8 @@ struct nk_style_property { float border; float rounding; struct nk_vec2 padding; + float color_factor; + float disabled_factor; struct nk_style_edit edit; struct nk_style_button inc_button; @@ -4935,6 +4957,8 @@ struct nk_style_chart { float border; float rounding; struct nk_vec2 padding; + float color_factor; + float disabled_factor; }; struct nk_style_combo { @@ -4966,6 +4990,8 @@ struct nk_style_combo { struct nk_vec2 content_padding; struct nk_vec2 button_padding; struct nk_vec2 spacing; + float color_factor; + float disabled_factor; }; struct nk_style_tab { @@ -4988,6 +5014,8 @@ struct nk_style_tab { float indent; struct nk_vec2 padding; struct nk_vec2 spacing; + float color_factor; + float disabled_factor; }; enum nk_style_header_align { @@ -5270,6 +5298,7 @@ struct nk_window { struct nk_popup_state popup; struct nk_edit_state edit; unsigned int scrolled; + nk_bool widgets_disabled; struct nk_table *tables; unsigned int table_count; diff --git a/src/nuklear_button.c b/src/nuklear_button.c index 2636b608d..98c205792 100644 --- a/src/nuklear_button.c +++ b/src/nuklear_button.c @@ -98,16 +98,16 @@ nk_draw_button(struct nk_command_buffer *out, background = &style->active; else background = &style->normal; - switch(background->type) { + switch (background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_rgb_factor(nk_white, style->color_factor), style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *bounds, style->rounding, background->data.color); - nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; } return background; @@ -157,6 +157,8 @@ nk_draw_button_text(struct nk_command_buffer *out, text.text = style->text_active; else text.text = style->text_normal; + text.text = nk_rgb_factor(text.text, style->color_factor); + text.padding = nk_vec2(0,0); nk_widget_text(out, *content, txt, len, &text, text_alignment, font); } @@ -204,6 +206,8 @@ nk_draw_button_symbol(struct nk_command_buffer *out, else if (state & NK_WIDGET_STATE_ACTIVED) sym = style->text_active; else sym = style->text_normal; + + sym = nk_rgb_factor(sym, style->color_factor); nk_draw_symbol(out, type, *content, bg, sym, 1, font); } NK_LIB nk_bool @@ -235,7 +239,7 @@ nk_draw_button_image(struct nk_command_buffer *out, nk_flags state, const struct nk_style_button *style, const struct nk_image *img) { nk_draw_button(out, bounds, state, style); - nk_draw_image(out, *content, img, nk_white); + nk_draw_image(out, *content, img, nk_rgb_factor(nk_white, style->color_factor)); } NK_LIB nk_bool nk_do_button_image(nk_flags *state, @@ -292,6 +296,8 @@ nk_draw_button_text_symbol(struct nk_command_buffer *out, text.text = style->text_normal; } + sym = nk_rgb_factor(sym, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor); text.padding = nk_vec2(0,0); nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font); nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); @@ -349,9 +355,10 @@ nk_draw_button_text_image(struct nk_command_buffer *out, text.text = style->text_active; else text.text = style->text_normal; - text.padding = nk_vec2(0,0); + text.text = nk_rgb_factor(text.text, style->color_factor); + text.padding = nk_vec2(0, 0); nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); - nk_draw_image(out, *image, img, nk_white); + nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor)); } NK_LIB nk_bool nk_do_button_text_image(nk_flags *state, @@ -456,7 +463,7 @@ nk_button_text_styled(struct nk_context *ctx, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, title, len, style->text_alignment, ctx->button_behavior, style, in, ctx->style.font); @@ -501,7 +508,7 @@ nk_button_color(struct nk_context *ctx, struct nk_color color) state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; button = ctx->style.button; button.normal = nk_style_item_color(color); @@ -533,7 +540,7 @@ nk_button_symbol_styled(struct nk_context *ctx, layout = win->layout; state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds, symbol, ctx->button_behavior, style, in, ctx->style.font); } @@ -566,7 +573,7 @@ nk_button_image_styled(struct nk_context *ctx, const struct nk_style_button *sty state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_image(&ctx->last_widget_state, &win->buffer, bounds, img, ctx->button_behavior, style, in); } @@ -600,7 +607,7 @@ nk_button_symbol_text_styled(struct nk_context *ctx, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds, symbol, text, len, align, ctx->button_behavior, style, ctx->style.font, in); @@ -647,7 +654,7 @@ nk_button_image_text_styled(struct nk_context *ctx, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, bounds, img, text, len, align, ctx->button_behavior, style, ctx->style.font, in); diff --git a/src/nuklear_chart.c b/src/nuklear_chart.c index d4fd90270..ba886e27a 100644 --- a/src/nuklear_chart.c +++ b/src/nuklear_chart.c @@ -48,7 +48,7 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, {struct nk_chart_slot *slot = &chart->slots[chart->slot++]; slot->type = type; slot->count = count; - slot->color = color; + slot->color = nk_rgb_factor(color, style->color_factor); slot->highlight = highlight; slot->min = NK_MIN(min_value, max_value); slot->max = NK_MAX(min_value, max_value); @@ -59,15 +59,15 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(&win->buffer, bounds, &background->data.image, nk_white); + nk_draw_image(&win->buffer, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(&win->buffer, bounds, &background->data.slice, nk_white); + nk_draw_image(&win->buffer, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(&win->buffer, bounds, style->rounding, style->border_color); + nk_fill_rect(&win->buffer, bounds, style->rounding, nk_rgb_factor(style->border_color, style->color_factor)); nk_fill_rect(&win->buffer, nk_shrink_rect(bounds, style->border), - style->rounding, style->background.data.color); + style->rounding, nk_rgb_factor(style->background.data.color, style->color_factor)); break; } return 1; @@ -84,6 +84,8 @@ nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type, struct nk_color color, struct nk_color highlight, int count, float min_value, float max_value) { + const struct nk_style_chart* style; + NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); @@ -91,12 +93,14 @@ nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type, if (!ctx || !ctx->current || !ctx->current->layout) return; if (ctx->current->layout->chart.slot >= NK_CHART_MAX_SLOT) return; + style = &ctx->style.chart; + /* add another slot into the graph */ {struct nk_chart *chart = &ctx->current->layout->chart; struct nk_chart_slot *slot = &chart->slots[chart->slot++]; slot->type = type; slot->count = count; - slot->color = color; + slot->color = nk_rgb_factor(color, style->color_factor); slot->highlight = highlight; slot->min = NK_MIN(min_value, max_value); slot->max = NK_MAX(min_value, max_value); @@ -114,7 +118,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, struct nk_chart *g, float value, int slot) { struct nk_panel *layout = win->layout; - const struct nk_input *i = &ctx->input; + const struct nk_input *i = ctx->current->widgets_disabled ? 0 : &ctx->input; struct nk_command_buffer *out = &win->buffer; nk_flags ret = 0; @@ -140,7 +144,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, bounds.w = bounds.h = 4; color = g->slots[slot].color; - if (!(layout->flags & NK_WINDOW_ROM) && + if (!(layout->flags & NK_WINDOW_ROM) && i && NK_INBOX(i->mouse.pos.x,i->mouse.pos.y, g->slots[slot].last.x-3, g->slots[slot].last.y-3, 6, 6)){ ret = nk_input_is_mouse_hovering_rect(i, bounds) ? NK_CHART_HOVERING : 0; ret |= (i->mouse.buttons[NK_BUTTON_LEFT].down && @@ -184,7 +188,7 @@ nk_chart_push_column(const struct nk_context *ctx, struct nk_window *win, struct nk_chart *chart, float value, int slot) { struct nk_command_buffer *out = &win->buffer; - const struct nk_input *in = &ctx->input; + const struct nk_input *in = ctx->current->widgets_disabled ? 0 : &ctx->input; struct nk_panel *layout = win->layout; float ratio; @@ -214,7 +218,7 @@ nk_chart_push_column(const struct nk_context *ctx, struct nk_window *win, item.x = item.x + ((float)chart->slots[slot].index); /* user chart bar selection */ - if (!(layout->flags & NK_WINDOW_ROM) && + if (!(layout->flags & NK_WINDOW_ROM) && in && NK_INBOX(in->mouse.pos.x,in->mouse.pos.y,item.x,item.y,item.w,item.h)) { ret = NK_CHART_HOVERING; ret |= (!in->mouse.buttons[NK_BUTTON_LEFT].down && diff --git a/src/nuklear_color.c b/src/nuklear_color.c index f2e1e8574..dc2e7fc0d 100644 --- a/src/nuklear_color.c +++ b/src/nuklear_color.c @@ -23,6 +23,16 @@ nk_parse_hex(const char *p, int length) return i; } NK_API struct nk_color +nk_rgb_factor(const struct nk_color col, const float factor) +{ + struct nk_color ret; + ret.r = col.r * factor; + ret.g = col.g * factor; + ret.b = col.b * factor; + ret.a = col.a; + return ret; +} +NK_API struct nk_color nk_rgba(int r, int g, int b, int a) { struct nk_color ret; diff --git a/src/nuklear_color_picker.c b/src/nuklear_color_picker.c index f9f7dfbc7..114c3c119 100644 --- a/src/nuklear_color_picker.c +++ b/src/nuklear_color_picker.c @@ -187,7 +187,7 @@ nk_color_pick(struct nk_context * ctx, struct nk_colorf *color, layout = win->layout; state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_color_picker(&ctx->last_widget_state, &win->buffer, color, fmt, bounds, nk_vec2(0,0), in, config->font); } diff --git a/src/nuklear_combo.c b/src/nuklear_combo.c index df1db0ad3..0e403b83c 100644 --- a/src/nuklear_combo.c +++ b/src/nuklear_combo.c @@ -67,7 +67,7 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, if (s == NK_WIDGET_INVALID) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -83,19 +83,21 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, text.text = style->combo.label_normal; } + text.text = nk_rgb_factor(text.text, style->combo.color_factor); + switch(background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -175,7 +177,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve if (s == NK_WIDGET_INVALID) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -188,14 +190,14 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -233,7 +235,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x; else bounds.w = header.w - 4 * style->combo.content_padding.x; - nk_fill_rect(&win->buffer, bounds, 0, color); + nk_fill_rect(&win->buffer, bounds, 0, nk_rgb_factor(color, style->combo.color_factor)); /* draw open/close button */ if (draw_button_symbol) @@ -268,7 +270,7 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct if (s == NK_WIDGET_INVALID) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -284,19 +286,21 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct symbol_color = style->combo.symbol_hover; } + symbol_color = nk_rgb_factor(symbol_color, style->combo.color_factor); + switch(background->type) { case NK_STYLE_ITEM_IMAGE: sym_background = nk_rgba(0, 0, 0, 0); - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: sym_background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: sym_background = background->data.color; - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -362,7 +366,7 @@ nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len s = nk_widget(&header, ctx); if (!s) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -381,19 +385,22 @@ nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len text.text = style->combo.label_normal; } + text.text = nk_rgb_factor(text.text, style->combo.color_factor); + symbol_color = nk_rgb_factor(symbol_color, style->combo.color_factor); + switch(background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -464,7 +471,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 if (s == NK_WIDGET_INVALID) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -477,14 +484,14 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 switch (background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -522,7 +529,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 bounds.w = (button.x - style->combo.content_padding.y) - bounds.x; else bounds.w = header.w - 2 * style->combo.content_padding.x; - nk_draw_image(&win->buffer, bounds, &img, nk_white); + nk_draw_image(&win->buffer, bounds, &img, nk_rgb_factor(nk_white, style->combo.color_factor)); /* draw open/close button */ if (draw_button_symbol) @@ -556,7 +563,7 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, s = nk_widget(&header, ctx); if (!s) return 0; - in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; @@ -572,19 +579,21 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, text.text = style->combo.label_normal; } + text.text = nk_rgb_factor(text.text, style->combo.color_factor); + switch(background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); - nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor)); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor)); break; } { @@ -623,7 +632,7 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, image.y = header.y + style->combo.content_padding.y; image.h = header.h - 2 * style->combo.content_padding.y; image.w = image.h; - nk_draw_image(&win->buffer, image, &img, nk_white); + nk_draw_image(&win->buffer, image, &img, nk_rgb_factor(nk_white, style->combo.color_factor)); /* draw label */ text.padding = nk_vec2(0,0); diff --git a/src/nuklear_contextual.c b/src/nuklear_contextual.c index 6d9358f09..f3e7db071 100644 --- a/src/nuklear_contextual.c +++ b/src/nuklear_contextual.c @@ -13,6 +13,7 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size, struct nk_window *win; struct nk_window *popup; struct nk_rect body; + struct nk_input* in; NK_STORAGE const struct nk_rect null_rect = {-1,-1,0,0}; int is_clicked = 0; @@ -33,35 +34,39 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size, /* check if currently active contextual is active */ popup = win->popup.win; is_open = (popup && win->popup.type == NK_PANEL_CONTEXTUAL); - is_clicked = nk_input_mouse_clicked(&ctx->input, NK_BUTTON_RIGHT, trigger_bounds); - if (win->popup.active_con && win->popup.con_count != win->popup.active_con) - return 0; - if (!is_open && win->popup.active_con) - win->popup.active_con = 0; - if ((!is_open && !is_clicked)) - return 0; + in = win->widgets_disabled ? 0 : &ctx->input; + if (in) { + is_clicked = nk_input_mouse_clicked(in, NK_BUTTON_RIGHT, trigger_bounds); + if (win->popup.active_con && win->popup.con_count != win->popup.active_con) + return 0; + if (!is_open && win->popup.active_con) + win->popup.active_con = 0; + if ((!is_open && !is_clicked)) + return 0; + + /* calculate contextual position on click */ + win->popup.active_con = win->popup.con_count; + if (is_clicked) { + body.x = in->mouse.pos.x; + body.y = in->mouse.pos.y; + } else { + body.x = popup->bounds.x; + body.y = popup->bounds.y; + } - /* calculate contextual position on click */ - win->popup.active_con = win->popup.con_count; - if (is_clicked) { - body.x = ctx->input.mouse.pos.x; - body.y = ctx->input.mouse.pos.y; - } else { - body.x = popup->bounds.x; - body.y = popup->bounds.y; - } - body.w = size.x; - body.h = size.y; + body.w = size.x; + body.h = size.y; - /* start nonblocking contextual popup */ - ret = nk_nonblock_begin(ctx, flags|NK_WINDOW_NO_SCROLLBAR, body, + /* start nonblocking contextual popup */ + ret = nk_nonblock_begin(ctx, flags | NK_WINDOW_NO_SCROLLBAR, body, null_rect, NK_PANEL_CONTEXTUAL); - if (ret) win->popup.type = NK_PANEL_CONTEXTUAL; - else { - win->popup.active_con = 0; - win->popup.type = NK_PANEL_NONE; - if (win->popup.win) - win->popup.win->flags = 0; + if (ret) win->popup.type = NK_PANEL_CONTEXTUAL; + else { + win->popup.active_con = 0; + win->popup.type = NK_PANEL_NONE; + if (win->popup.win) + win->popup.win->flags = 0; + } } return ret; } diff --git a/src/nuklear_edit.c b/src/nuklear_edit.c index 8cab48eba..4157dd8e0 100644 --- a/src/nuklear_edit.c +++ b/src/nuklear_edit.c @@ -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; txt.padding = nk_vec2(0,0); txt.background = background; @@ -331,14 +334,14 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, /* draw background frame */ switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, bounds, &background->data.image, nk_white); + nk_draw_image(out, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, bounds, style->rounding, background->data.color); - nk_stroke_rect(out, bounds, style->rounding, style->border, style->border_color); + nk_fill_rect(out, bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; }} @@ -547,6 +550,8 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, else background_color = background->data.color; + cursor_color = nk_rgb_factor(cursor_color, style->color_factor); + cursor_text_color = nk_rgb_factor(cursor_text_color, style->color_factor); if (edit->select_start == edit->select_end) { /* no selection so just draw the complete text */ @@ -654,6 +659,10 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out, background_color = nk_rgba(0,0,0,0); else background_color = background->data.color; + + background_color = nk_rgb_factor(background_color, style->color_factor); + text_color = nk_rgb_factor(text_color, style->color_factor); + nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, area.y - edit->scrollbar.y, 0, begin, l, row_height, font, background_color, text_color, nk_false); @@ -773,6 +782,8 @@ nk_edit_buffer(struct nk_context *ctx, nk_flags flags, style = &ctx->style; state = nk_widget(&bounds, ctx); if (!state) return state; + else if (state == NK_WIDGET_DISABLED) + flags |= NK_EDIT_READ_ONLY; in = (win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; /* check if edit is currently hot item */ diff --git a/src/nuklear_menu.c b/src/nuklear_menu.c index 60fe692fc..00ec5e11f 100644 --- a/src/nuklear_menu.c +++ b/src/nuklear_menu.c @@ -128,7 +128,7 @@ nk_menu_begin_text(struct nk_context *ctx, const char *title, int len, win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, header, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) is_clicked = nk_true; @@ -158,7 +158,7 @@ nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_image(&ctx->last_widget_state, &win->buffer, header, img, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in)) is_clicked = nk_true; @@ -183,7 +183,7 @@ nk_menu_begin_symbol(struct nk_context *ctx, const char *id, win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, header, sym, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) is_clicked = nk_true; @@ -208,7 +208,7 @@ nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len, win = ctx->current; state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, header, img, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, ctx->style.font, in)) @@ -241,7 +241,7 @@ nk_menu_begin_symbol_text(struct nk_context *ctx, const char *title, int len, state = nk_widget(&header, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; if (nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, header, sym, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, ctx->style.font, in)) is_clicked = nk_true; diff --git a/src/nuklear_progress.c b/src/nuklear_progress.c index 65578ca03..4f487d744 100644 --- a/src/nuklear_progress.c +++ b/src/nuklear_progress.c @@ -62,28 +62,28 @@ nk_draw_progress(struct nk_command_buffer *out, nk_flags state, /* draw background */ switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *bounds, style->rounding, background->data.color); - nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; } /* draw cursor */ switch(cursor->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *scursor, &cursor->data.image, nk_white); + nk_draw_image(out, *scursor, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *scursor, &cursor->data.slice, nk_white); + nk_draw_nine_slice(out, *scursor, &cursor->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *scursor, style->rounding, cursor->data.color); - nk_stroke_rect(out, *scursor, style->rounding, style->border, style->border_color); + nk_fill_rect(out, *scursor, style->rounding, nk_rgb_factor(cursor->data.color, style->color_factor)); + nk_stroke_rect(out, *scursor, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; } } @@ -143,7 +143,7 @@ nk_progress(struct nk_context *ctx, nk_size *cur, nk_size max, nk_bool is_modify state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; old_value = *cur; *cur = nk_do_progress(&ctx->last_widget_state, &win->buffer, bounds, *cur, max, is_modifyable, &style->progress, in); diff --git a/src/nuklear_property.c b/src/nuklear_property.c index 34708731d..2a34eb767 100644 --- a/src/nuklear_property.c +++ b/src/nuklear_property.c @@ -85,20 +85,22 @@ nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property * text.text = style->label_normal; } + text.text = nk_rgb_factor(text.text, style->color_factor); + /* draw background */ switch(background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(out, *bounds, style->rounding, background->data.color); - nk_stroke_rect(out, *bounds, style->rounding, style->border, background->data.color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(background->data.color, style->color_factor)); break; } @@ -383,7 +385,7 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant old_state = *state; ctx->text_edit.clip = ctx->clip; in = ((s == NK_WIDGET_ROM && !win->property.active) || - layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED) ? 0 : &ctx->input; nk_do_property(&ctx->last_widget_state, &win->buffer, bounds, name, variant, inc_per_pixel, buffer, len, state, cursor, select_begin, select_end, &style->property, filter, in, style->font, &ctx->text_edit, diff --git a/src/nuklear_selectable.c b/src/nuklear_selectable.c index e5f72780a..3f4bfc4b1 100644 --- a/src/nuklear_selectable.c +++ b/src/nuklear_selectable.c @@ -41,23 +41,26 @@ nk_draw_selectable(struct nk_command_buffer *out, text.text = style->text_normal_active; } } + + text.text = nk_rgb_factor(text.text, style->color_factor); + /* draw selectable background and text */ switch (background->type) { case NK_STYLE_ITEM_IMAGE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: text.background = nk_rgba(0, 0, 0, 0); - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(out, *bounds, style->rounding, background->data.color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); break; } if (icon) { - if (img) nk_draw_image(out, *icon, img, nk_white); + if (img) nk_draw_image(out, *icon, img, nk_rgb_factor(nk_white, style->color_factor)); else nk_draw_symbol(out, sym, *icon, text.background, text.text, 1, font); } nk_widget_text(out, *bounds, string, len, &text, align, font); @@ -218,7 +221,7 @@ nk_selectable_text(struct nk_context *ctx, const char *str, int len, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_selectable(&ctx->last_widget_state, &win->buffer, bounds, str, len, align, value, &style->selectable, in, style->font); } @@ -247,7 +250,7 @@ nk_selectable_image_text(struct nk_context *ctx, struct nk_image img, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_selectable_image(&ctx->last_widget_state, &win->buffer, bounds, str, len, align, value, &img, &style->selectable, in, style->font); } @@ -276,7 +279,7 @@ nk_selectable_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, state = nk_widget(&bounds, ctx); if (!state) return 0; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; return nk_do_selectable_symbol(&ctx->last_widget_state, &win->buffer, bounds, str, len, align, value, sym, &style->selectable, in, style->font); } diff --git a/src/nuklear_slider.c b/src/nuklear_slider.c index 188f7f46a..872cbd11e 100644 --- a/src/nuklear_slider.c +++ b/src/nuklear_slider.c @@ -78,6 +78,7 @@ nk_draw_slider(struct nk_command_buffer *out, nk_flags state, bar_color = style->bar_normal; cursor = &style->cursor_normal; } + /* calculate slider background bar */ bar.x = bounds->x; bar.y = (visual_cursor->y + visual_cursor->h/2) - bounds->h/12; @@ -93,26 +94,26 @@ nk_draw_slider(struct nk_command_buffer *out, nk_flags state, /* draw background */ switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *bounds, &background->data.image, nk_white); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *bounds, style->rounding, background->data.color); - nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); break; } /* draw slider bar */ - nk_fill_rect(out, bar, style->rounding, bar_color); - nk_fill_rect(out, fill, style->rounding, style->bar_filled); + nk_fill_rect(out, bar, style->rounding, nk_rgb_factor(bar_color, style->color_factor)); + nk_fill_rect(out, fill, style->rounding, nk_rgb_factor(style->bar_filled, style->color_factor)); /* draw cursor */ if (cursor->type == NK_STYLE_ITEM_IMAGE) - nk_draw_image(out, *visual_cursor, &cursor->data.image, nk_white); + nk_draw_image(out, *visual_cursor, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); else - nk_fill_circle(out, *visual_cursor, cursor->data.color); + nk_fill_circle(out, *visual_cursor, nk_rgb_factor(cursor->data.color, style->color_factor)); } NK_LIB float nk_do_slider(nk_flags *state, @@ -230,7 +231,7 @@ nk_slider_float(struct nk_context *ctx, float min_value, float *value, float max state = nk_widget(&bounds, ctx); if (!state) return ret; - in = (/*state == NK_WIDGET_ROM || */ layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (/*state == NK_WIDGET_ROM || */ state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; old_value = *value; *value = nk_do_slider(&ctx->last_widget_state, &win->buffer, bounds, min_value, diff --git a/src/nuklear_style.c b/src/nuklear_style.c index 0e0851e0a..be9026b1e 100644 --- a/src/nuklear_style.c +++ b/src/nuklear_style.c @@ -113,6 +113,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) text = &style->text; text->color = table[NK_COLOR_TEXT]; text->padding = nk_vec2(0,0); + text->color_factor = 1.0f; + text->disabled_factor = 0.5f; /* default button */ button = &style->button; @@ -132,6 +134,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 4.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -152,6 +156,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -172,6 +178,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 1.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -193,6 +201,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) toggle->border_color = nk_rgba(0,0,0,0); toggle->border = 0.0f; toggle->spacing = 4; + toggle->color_factor = 1.0f; + toggle->disabled_factor = 0.5f; /* option toggle */ toggle = &style->option; @@ -212,6 +222,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) toggle->border_color = nk_rgba(0,0,0,0); toggle->border = 0.0f; toggle->spacing = 4; + toggle->color_factor = 1.0f; + toggle->disabled_factor = 0.5f; /* selectable */ select = &style->selectable; @@ -233,6 +245,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) select->touch_padding = nk_vec2(0,0); select->userdata = nk_handle_ptr(0); select->rounding = 0.0f; + select->color_factor = 1.0f; + select->disabled_factor = 0.5f; select->draw_begin = 0; select->draw_end = 0; @@ -258,6 +272,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) slider->show_buttons = nk_false; slider->bar_height = 8; slider->rounding = 0; + slider->color_factor = 1.0f; + slider->disabled_factor = 0.5f; slider->draw_begin = 0; slider->draw_end = 0; @@ -277,6 +293,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->slider.dec_button = style->slider.inc_button; @@ -298,6 +316,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) prog->border = 0; prog->cursor_rounding = 0; prog->cursor_border = 0; + prog->color_factor = 1.0f; + prog->disabled_factor = 0.5f; prog->draw_begin = 0; prog->draw_end = 0; @@ -321,6 +341,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) scroll->rounding = 0; scroll->border_cursor = 0; scroll->rounding_cursor = 0; + scroll->color_factor = 1.0f; + scroll->disabled_factor = 0.5f; scroll->draw_begin = 0; scroll->draw_end = 0; style->scrollv = style->scrollh; @@ -341,6 +363,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->scrollh.dec_button = style->scrollh.inc_button; @@ -372,6 +396,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) edit->cursor_size = 4; edit->border = 1; edit->rounding = 0; + edit->color_factor = 1.0f; + edit->disabled_factor = 0.5f; /* property */ property = &style->property; @@ -391,6 +417,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) property->rounding = 10; property->draw_begin = 0; property->draw_end = 0; + property->color_factor = 1.0f; + property->disabled_factor = 0.5f; /* property buttons */ button = &style->property.dec_button; @@ -409,6 +437,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->property.inc_button = style->property.dec_button; @@ -435,6 +465,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) edit->cursor_size = 8; edit->border = 0; edit->rounding = 0; + edit->color_factor = 1.0f; + edit->disabled_factor = 0.5f; /* chart */ chart = &style->chart; @@ -446,6 +478,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) chart->padding = nk_vec2(4,4); chart->border = 0; chart->rounding = 0; + chart->color_factor = 1.0f; + chart->disabled_factor = 0.5f; /* combo */ combo = &style->combo; @@ -464,6 +498,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) combo->spacing = nk_vec2(4,0); combo->border = 1; combo->rounding = 0; + combo->color_factor = 1.0f; + combo->disabled_factor = 0.5f; /* combo button */ button = &style->combo.button; @@ -482,6 +518,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -497,6 +535,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) tab->indent = 10.0f; tab->border = 1; tab->rounding = 0; + tab->color_factor = 1.0f; + tab->disabled_factor = 0.5f; /* tab button */ button = &style->tab.tab_minimize_button; @@ -515,6 +555,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->tab.tab_maximize_button =*button; @@ -536,6 +578,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; style->tab.node_maximize_button =*button; @@ -573,6 +617,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; @@ -593,6 +639,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; + button->color_factor = 1.0f; + button->disabled_factor = 0.5f; button->draw_begin = 0; button->draw_end = 0; diff --git a/src/nuklear_text.c b/src/nuklear_text.c index 1ed967ea2..3df91498e 100644 --- a/src/nuklear_text.c +++ b/src/nuklear_text.c @@ -114,7 +114,7 @@ nk_text_colored(struct nk_context *ctx, const char *str, int len, text.padding.x = item_padding.x; text.padding.y = item_padding.y; text.background = style->window.background; - text.text = color; + text.text = nk_rgb_factor(color, style->text.color_factor); nk_widget_text(&win->buffer, bounds, str, len, &text, alignment, style->font); } NK_API void @@ -141,7 +141,7 @@ nk_text_wrap_colored(struct nk_context *ctx, const char *str, text.padding.x = item_padding.x; text.padding.y = item_padding.y; text.background = style->window.background; - text.text = color; + text.text = nk_rgb_factor(color, style->text.color_factor); nk_widget_text_wrap(&win->buffer, bounds, str, len, &text, style->font); } #ifdef NK_INCLUDE_STANDARD_VARARGS diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index 0644a8078..41121c34e 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -47,14 +47,16 @@ nk_draw_checkbox(struct nk_command_buffer *out, text.text = style->text_normal; } + text.text = nk_rgb_factor(text.text, style->color_factor); + /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { - nk_fill_rect(out, *selector, 0, style->border_color); - nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, background->data.color); - } else nk_draw_image(out, *selector, &background->data.image, nk_white); + nk_fill_rect(out, *selector, 0, nk_rgb_factor(style->border_color, style->color_factor)); + nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, nk_rgb_factor(background->data.color, style->color_factor)); + } else nk_draw_image(out, *selector, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); if (active) { if (cursor->type == NK_STYLE_ITEM_IMAGE) - nk_draw_image(out, *cursors, &cursor->data.image, nk_white); + nk_draw_image(out, *cursors, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); else nk_fill_rect(out, *cursors, 0, cursor->data.color); } @@ -89,14 +91,16 @@ nk_draw_option(struct nk_command_buffer *out, text.text = style->text_normal; } + text.text = nk_rgb_factor(text.text, style->color_factor); + /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { - nk_fill_circle(out, *selector, style->border_color); - nk_fill_circle(out, nk_shrink_rect(*selector, style->border), background->data.color); - } else nk_draw_image(out, *selector, &background->data.image, nk_white); + nk_fill_circle(out, *selector, nk_rgb_factor(style->border_color, style->color_factor)); + nk_fill_circle(out, nk_shrink_rect(*selector, style->border), nk_rgb_factor(background->data.color, style->color_factor)); + } else nk_draw_image(out, *selector, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); if (active) { if (cursor->type == NK_STYLE_ITEM_IMAGE) - nk_draw_image(out, *cursors, &cursor->data.image, nk_white); + nk_draw_image(out, *cursors, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); else nk_fill_circle(out, *cursors, cursor->data.color); } @@ -195,7 +199,7 @@ nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active) state = nk_widget(&bounds, ctx); if (!state) return active; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active, text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font); return active; @@ -290,7 +294,7 @@ nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_act state = nk_widget(&bounds, ctx); if (!state) return (int)state; - in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &is_active, text, len, NK_TOGGLE_OPTION, &style->option, in, style->font); return is_active; diff --git a/src/nuklear_widget.c b/src/nuklear_widget.c index 2e78cd5ca..f2a243c04 100644 --- a/src/nuklear_widget.c +++ b/src/nuklear_widget.c @@ -175,6 +175,8 @@ nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) return NK_WIDGET_INVALID; + if (win->widgets_disabled) + return NK_WIDGET_DISABLED; if (!NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, v.x, v.y, v.w, v.h)) return NK_WIDGET_ROM; return NK_WIDGET_VALID; @@ -227,4 +229,101 @@ nk_spacing(struct nk_context *ctx, int cols) nk_panel_alloc_space(&none, ctx); } layout->row.index = index; } +NK_API void +nk_widget_disable_begin(struct nk_context* ctx) +{ + struct nk_window* win; + struct nk_style* style; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + + if (!ctx || !ctx->current) + return; + + win = ctx->current; + style = &ctx->style; + + win->widgets_disabled = nk_true; + + style->button.color_factor = style->button.disabled_factor; + style->chart.color_factor = style->chart.disabled_factor; + style->checkbox.color_factor = style->checkbox.disabled_factor; + style->combo.color_factor = style->combo.disabled_factor; + style->combo.button.color_factor = style->combo.button.disabled_factor; + style->contextual_button.color_factor = style->contextual_button.disabled_factor; + style->edit.color_factor = style->edit.disabled_factor; + style->edit.scrollbar.color_factor = style->edit.scrollbar.disabled_factor; + style->menu_button.color_factor = style->menu_button.disabled_factor; + style->option.color_factor = style->option.disabled_factor; + style->progress.color_factor = style->progress.disabled_factor; + style->property.color_factor = style->property.disabled_factor; + style->property.inc_button.color_factor = style->property.inc_button.disabled_factor; + style->property.dec_button.color_factor = style->property.dec_button.disabled_factor; + style->property.edit.color_factor = style->property.edit.disabled_factor; + style->scrollh.color_factor = style->scrollh.disabled_factor; + style->scrollh.inc_button.color_factor = style->scrollh.inc_button.disabled_factor; + style->scrollh.dec_button.color_factor = style->scrollh.dec_button.disabled_factor; + style->scrollv.color_factor = style->scrollv.disabled_factor; + style->scrollv.inc_button.color_factor = style->scrollv.inc_button.disabled_factor; + style->scrollv.dec_button.color_factor = style->scrollv.dec_button.disabled_factor; + style->selectable.color_factor = style->selectable.disabled_factor; + style->slider.color_factor = style->slider.disabled_factor; + style->slider.inc_button.color_factor = style->slider.inc_button.disabled_factor; + style->slider.dec_button.color_factor = style->slider.dec_button.disabled_factor; + style->tab.color_factor = style->tab.disabled_factor; + style->tab.node_maximize_button.color_factor = style->tab.node_maximize_button.disabled_factor; + style->tab.node_minimize_button.color_factor = style->tab.node_minimize_button.disabled_factor; + style->tab.tab_maximize_button.color_factor = style->tab.tab_maximize_button.disabled_factor; + style->tab.tab_minimize_button.color_factor = style->tab.tab_minimize_button.disabled_factor; + style->text.color_factor = style->text.disabled_factor; +} +NK_API void +nk_widget_disable_end(struct nk_context* ctx) +{ + struct nk_window* win; + struct nk_style* style; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + + if (!ctx || !ctx->current) + return; + + win = ctx->current; + style = &ctx->style; + + win->widgets_disabled = nk_false; + + style->button.color_factor = 1.0f; + style->chart.color_factor = 1.0f; + style->checkbox.color_factor = 1.0f; + style->combo.color_factor = 1.0f; + style->combo.button.color_factor = 1.0f; + style->contextual_button.color_factor = 1.0f; + style->edit.color_factor = 1.0f; + style->edit.scrollbar.color_factor = 1.0f; + style->menu_button.color_factor = 1.0f; + style->option.color_factor = 1.0f; + style->progress.color_factor = 1.0f; + style->property.color_factor = 1.0f; + style->property.inc_button.color_factor = 1.0f; + style->property.dec_button.color_factor = 1.0f; + style->property.edit.color_factor = 1.0f; + style->scrollh.color_factor = 1.0f; + style->scrollh.inc_button.color_factor = 1.0f; + style->scrollh.dec_button.color_factor = 1.0f; + style->scrollv.color_factor = 1.0f; + style->scrollv.inc_button.color_factor = 1.0f; + style->scrollv.dec_button.color_factor = 1.0f; + style->selectable.color_factor = 1.0f; + style->slider.color_factor = 1.0f; + style->slider.inc_button.color_factor = 1.0f; + style->slider.dec_button.color_factor = 1.0f; + style->tab.color_factor = 1.0f; + style->tab.node_maximize_button.color_factor = 1.0f; + style->tab.node_minimize_button.color_factor = 1.0f; + style->tab.tab_maximize_button.color_factor = 1.0f; + style->tab.tab_minimize_button.color_factor = 1.0f; + style->text.color_factor = 1.0f; +} diff --git a/src/nuklear_window.c b/src/nuklear_window.c index 486b912b3..240604daf 100644 --- a/src/nuklear_window.c +++ b/src/nuklear_window.c @@ -180,6 +180,7 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, NK_MEMCPY(win->name_string, name, name_length); win->name_string[name_length] = 0; win->popup.win = 0; + win->widgets_disabled = false; if (!ctx->active) ctx->active = win; } else { From 25cda15319d77c53ef763a233c7801381057caab Mon Sep 17 00:00:00 2001 From: Yukyduky Date: Fri, 13 Oct 2023 11:48:59 +0200 Subject: [PATCH 02/10] Fixed two copy paste mistakes --- nuklear.h | 5 +++-- src/nuklear_button.c | 2 +- src/nuklear_chart.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/nuklear.h b/nuklear.h index 0d9b9a2b3..060401738 100644 --- a/nuklear.h +++ b/nuklear.h @@ -24023,7 +24023,7 @@ nk_draw_button(struct nk_command_buffer *out, nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_rgb_factor(nk_white, style->color_factor), style->color_factor)); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); @@ -28421,7 +28421,7 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, nk_draw_image(&win->buffer, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_image(&win->buffer, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_nine_slice(&win->buffer, bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: nk_fill_rect(&win->buffer, bounds, style->rounding, nk_rgb_factor(style->border_color, style->color_factor)); @@ -29905,6 +29905,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() /// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly /// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 diff --git a/src/nuklear_button.c b/src/nuklear_button.c index 98c205792..423e0df1d 100644 --- a/src/nuklear_button.c +++ b/src/nuklear_button.c @@ -103,7 +103,7 @@ nk_draw_button(struct nk_command_buffer *out, nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_rgb_factor(nk_white, style->color_factor), style->color_factor)); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); diff --git a/src/nuklear_chart.c b/src/nuklear_chart.c index ba886e27a..b71caf288 100644 --- a/src/nuklear_chart.c +++ b/src/nuklear_chart.c @@ -62,7 +62,7 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, nk_draw_image(&win->buffer, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_image(&win->buffer, bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_nine_slice(&win->buffer, bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); break; case NK_STYLE_ITEM_COLOR: nk_fill_rect(&win->buffer, bounds, style->rounding, nk_rgb_factor(style->border_color, style->color_factor)); From 5a6569a2c9bde51b2dbe3b62d9a41091ec036adb Mon Sep 17 00:00:00 2001 From: Yukyduky Date: Tue, 17 Oct 2023 20:04:14 +0200 Subject: [PATCH 03/10] Added disabled factor & performance improvement Added NK_WIDGET_DISABLED_FACTOR, global factor for disabled color --- nuklear.h | 67 +++++++++++++++++++++++---------------------- src/nuklear.h | 5 +++- src/nuklear_color.c | 14 +++++----- src/nuklear_style.c | 48 ++++++++++++++++---------------- 4 files changed, 70 insertions(+), 64 deletions(-) diff --git a/nuklear.h b/nuklear.h index dec674b10..ec1569ef2 100644 --- a/nuklear.h +++ b/nuklear.h @@ -3609,6 +3609,9 @@ NK_API void nk_menu_end(struct nk_context*); * STYLE * * ============================================================================= */ + +#define NK_WIDGET_DISABLED_FACTOR 0.5f + enum nk_style_colors { NK_COLOR_TEXT, NK_COLOR_WINDOW, @@ -3685,7 +3688,7 @@ NK_API struct nk_color nk_rgb_f(float r, float g, float b); NK_API struct nk_color nk_rgb_fv(const float *rgb); NK_API struct nk_color nk_rgb_cf(struct nk_colorf c); NK_API struct nk_color nk_rgb_hex(const char *rgb); -NK_API struct nk_color nk_rgb_factor(const struct nk_color col, const float factor); +NK_API struct nk_color nk_rgb_factor(struct nk_color col, const float factor); NK_API struct nk_color nk_rgba(int r, int g, int b, int a); NK_API struct nk_color nk_rgba_u32(nk_uint); @@ -7632,14 +7635,14 @@ nk_parse_hex(const char *p, int length) return i; } NK_API struct nk_color -nk_rgb_factor(const struct nk_color col, const float factor) +nk_rgb_factor(struct nk_color col, const float factor) { - struct nk_color ret; - ret.r = col.r * factor; - ret.g = col.g * factor; - ret.b = col.b * factor; - ret.a = col.a; - return ret; + if (factor == 1.0f) + return col; + col.r *= factor; + col.g *= factor; + col.b *= factor; + return col; } NK_API struct nk_color nk_rgba(int r, int g, int b, int a) @@ -18280,7 +18283,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) text->color = table[NK_COLOR_TEXT]; text->padding = nk_vec2(0,0); text->color_factor = 1.0f; - text->disabled_factor = 0.5f; + text->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* default button */ button = &style->button; @@ -18301,7 +18304,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 1.0f; button->rounding = 4.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18323,7 +18326,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18345,7 +18348,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 1.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18368,7 +18371,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) toggle->border = 0.0f; toggle->spacing = 4; toggle->color_factor = 1.0f; - toggle->disabled_factor = 0.5f; + toggle->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* option toggle */ toggle = &style->option; @@ -18389,7 +18392,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) toggle->border = 0.0f; toggle->spacing = 4; toggle->color_factor = 1.0f; - toggle->disabled_factor = 0.5f; + toggle->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* selectable */ select = &style->selectable; @@ -18412,7 +18415,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) select->userdata = nk_handle_ptr(0); select->rounding = 0.0f; select->color_factor = 1.0f; - select->disabled_factor = 0.5f; + select->disabled_factor = NK_WIDGET_DISABLED_FACTOR; select->draw_begin = 0; select->draw_end = 0; @@ -18439,7 +18442,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) slider->bar_height = 8; slider->rounding = 0; slider->color_factor = 1.0f; - slider->disabled_factor = 0.5f; + slider->disabled_factor = NK_WIDGET_DISABLED_FACTOR; slider->draw_begin = 0; slider->draw_end = 0; @@ -18460,7 +18463,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 1.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->slider.dec_button = style->slider.inc_button; @@ -18483,7 +18486,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) prog->cursor_rounding = 0; prog->cursor_border = 0; prog->color_factor = 1.0f; - prog->disabled_factor = 0.5f; + prog->disabled_factor = NK_WIDGET_DISABLED_FACTOR; prog->draw_begin = 0; prog->draw_end = 0; @@ -18508,7 +18511,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) scroll->border_cursor = 0; scroll->rounding_cursor = 0; scroll->color_factor = 1.0f; - scroll->disabled_factor = 0.5f; + scroll->disabled_factor = NK_WIDGET_DISABLED_FACTOR; scroll->draw_begin = 0; scroll->draw_end = 0; style->scrollv = style->scrollh; @@ -18530,7 +18533,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 1.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->scrollh.dec_button = style->scrollh.inc_button; @@ -18563,7 +18566,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) edit->border = 1; edit->rounding = 0; edit->color_factor = 1.0f; - edit->disabled_factor = 0.5f; + edit->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* property */ property = &style->property; @@ -18584,7 +18587,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) property->draw_begin = 0; property->draw_end = 0; property->color_factor = 1.0f; - property->disabled_factor = 0.5f; + property->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* property buttons */ button = &style->property.dec_button; @@ -18604,7 +18607,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->property.inc_button = style->property.dec_button; @@ -18632,7 +18635,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) edit->border = 0; edit->rounding = 0; edit->color_factor = 1.0f; - edit->disabled_factor = 0.5f; + edit->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* chart */ chart = &style->chart; @@ -18645,7 +18648,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) chart->border = 0; chart->rounding = 0; chart->color_factor = 1.0f; - chart->disabled_factor = 0.5f; + chart->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* combo */ combo = &style->combo; @@ -18665,7 +18668,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) combo->border = 1; combo->rounding = 0; combo->color_factor = 1.0f; - combo->disabled_factor = 0.5f; + combo->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* combo button */ button = &style->combo.button; @@ -18685,7 +18688,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18702,7 +18705,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) tab->border = 1; tab->rounding = 0; tab->color_factor = 1.0f; - tab->disabled_factor = 0.5f; + tab->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* tab button */ button = &style->tab.tab_minimize_button; @@ -18722,7 +18725,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->tab.tab_maximize_button =*button; @@ -18745,7 +18748,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->tab.node_maximize_button =*button; @@ -18784,7 +18787,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18806,7 +18809,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; diff --git a/src/nuklear.h b/src/nuklear.h index 7dc90aba2..a16607bb5 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -3387,6 +3387,9 @@ NK_API void nk_menu_end(struct nk_context*); * STYLE * * ============================================================================= */ + +#define NK_WIDGET_DISABLED_FACTOR 0.5f + enum nk_style_colors { NK_COLOR_TEXT, NK_COLOR_WINDOW, @@ -3463,7 +3466,7 @@ NK_API struct nk_color nk_rgb_f(float r, float g, float b); NK_API struct nk_color nk_rgb_fv(const float *rgb); NK_API struct nk_color nk_rgb_cf(struct nk_colorf c); NK_API struct nk_color nk_rgb_hex(const char *rgb); -NK_API struct nk_color nk_rgb_factor(const struct nk_color col, const float factor); +NK_API struct nk_color nk_rgb_factor(struct nk_color col, const float factor); NK_API struct nk_color nk_rgba(int r, int g, int b, int a); NK_API struct nk_color nk_rgba_u32(nk_uint); diff --git a/src/nuklear_color.c b/src/nuklear_color.c index dc2e7fc0d..17969f355 100644 --- a/src/nuklear_color.c +++ b/src/nuklear_color.c @@ -23,14 +23,14 @@ nk_parse_hex(const char *p, int length) return i; } NK_API struct nk_color -nk_rgb_factor(const struct nk_color col, const float factor) +nk_rgb_factor(struct nk_color col, const float factor) { - struct nk_color ret; - ret.r = col.r * factor; - ret.g = col.g * factor; - ret.b = col.b * factor; - ret.a = col.a; - return ret; + if (factor == 1.0f) + return col; + col.r *= factor; + col.g *= factor; + col.b *= factor; + return col; } NK_API struct nk_color nk_rgba(int r, int g, int b, int a) diff --git a/src/nuklear_style.c b/src/nuklear_style.c index be9026b1e..b97ad712e 100644 --- a/src/nuklear_style.c +++ b/src/nuklear_style.c @@ -114,7 +114,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) text->color = table[NK_COLOR_TEXT]; text->padding = nk_vec2(0,0); text->color_factor = 1.0f; - text->disabled_factor = 0.5f; + text->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* default button */ button = &style->button; @@ -135,7 +135,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 1.0f; button->rounding = 4.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -157,7 +157,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -179,7 +179,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 1.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -202,7 +202,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) toggle->border = 0.0f; toggle->spacing = 4; toggle->color_factor = 1.0f; - toggle->disabled_factor = 0.5f; + toggle->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* option toggle */ toggle = &style->option; @@ -223,7 +223,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) toggle->border = 0.0f; toggle->spacing = 4; toggle->color_factor = 1.0f; - toggle->disabled_factor = 0.5f; + toggle->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* selectable */ select = &style->selectable; @@ -246,7 +246,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) select->userdata = nk_handle_ptr(0); select->rounding = 0.0f; select->color_factor = 1.0f; - select->disabled_factor = 0.5f; + select->disabled_factor = NK_WIDGET_DISABLED_FACTOR; select->draw_begin = 0; select->draw_end = 0; @@ -273,7 +273,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) slider->bar_height = 8; slider->rounding = 0; slider->color_factor = 1.0f; - slider->disabled_factor = 0.5f; + slider->disabled_factor = NK_WIDGET_DISABLED_FACTOR; slider->draw_begin = 0; slider->draw_end = 0; @@ -294,7 +294,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 1.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->slider.dec_button = style->slider.inc_button; @@ -317,7 +317,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) prog->cursor_rounding = 0; prog->cursor_border = 0; prog->color_factor = 1.0f; - prog->disabled_factor = 0.5f; + prog->disabled_factor = NK_WIDGET_DISABLED_FACTOR; prog->draw_begin = 0; prog->draw_end = 0; @@ -342,7 +342,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) scroll->border_cursor = 0; scroll->rounding_cursor = 0; scroll->color_factor = 1.0f; - scroll->disabled_factor = 0.5f; + scroll->disabled_factor = NK_WIDGET_DISABLED_FACTOR; scroll->draw_begin = 0; scroll->draw_end = 0; style->scrollv = style->scrollh; @@ -364,7 +364,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 1.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->scrollh.dec_button = style->scrollh.inc_button; @@ -397,7 +397,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) edit->border = 1; edit->rounding = 0; edit->color_factor = 1.0f; - edit->disabled_factor = 0.5f; + edit->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* property */ property = &style->property; @@ -418,7 +418,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) property->draw_begin = 0; property->draw_end = 0; property->color_factor = 1.0f; - property->disabled_factor = 0.5f; + property->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* property buttons */ button = &style->property.dec_button; @@ -438,7 +438,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->property.inc_button = style->property.dec_button; @@ -466,7 +466,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) edit->border = 0; edit->rounding = 0; edit->color_factor = 1.0f; - edit->disabled_factor = 0.5f; + edit->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* chart */ chart = &style->chart; @@ -479,7 +479,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) chart->border = 0; chart->rounding = 0; chart->color_factor = 1.0f; - chart->disabled_factor = 0.5f; + chart->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* combo */ combo = &style->combo; @@ -499,7 +499,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) combo->border = 1; combo->rounding = 0; combo->color_factor = 1.0f; - combo->disabled_factor = 0.5f; + combo->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* combo button */ button = &style->combo.button; @@ -519,7 +519,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -536,7 +536,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) tab->border = 1; tab->rounding = 0; tab->color_factor = 1.0f; - tab->disabled_factor = 0.5f; + tab->disabled_factor = NK_WIDGET_DISABLED_FACTOR; /* tab button */ button = &style->tab.tab_minimize_button; @@ -556,7 +556,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->tab.tab_maximize_button =*button; @@ -579,7 +579,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; style->tab.node_maximize_button =*button; @@ -618,7 +618,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -640,7 +640,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->border = 0.0f; button->rounding = 0.0f; button->color_factor = 1.0f; - button->disabled_factor = 0.5f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; From b1fcf9244fe316ea53592f6f6af1acad6ee8667b Mon Sep 17 00:00:00 2001 From: Yukyduky Date: Wed, 18 Oct 2023 22:33:05 +0200 Subject: [PATCH 04/10] Changed a false to an nk_false --- nuklear.h | 2 +- src/nuklear_window.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nuklear.h b/nuklear.h index ec1569ef2..cf703585a 100644 --- a/nuklear.h +++ b/nuklear.h @@ -20359,7 +20359,7 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, NK_MEMCPY(win->name_string, name, name_length); win->name_string[name_length] = 0; win->popup.win = 0; - win->widgets_disabled = false; + win->widgets_disabled = nk_false; if (!ctx->active) ctx->active = win; } else { diff --git a/src/nuklear_window.c b/src/nuklear_window.c index d771e21a9..2e382b27f 100644 --- a/src/nuklear_window.c +++ b/src/nuklear_window.c @@ -180,7 +180,7 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, NK_MEMCPY(win->name_string, name, name_length); win->name_string[name_length] = 0; win->popup.win = 0; - win->widgets_disabled = false; + win->widgets_disabled = nk_false; if (!ctx->active) ctx->active = win; } else { From 4545d184d3a8537d5470116f70ab85ea9456c78b Mon Sep 17 00:00:00 2001 From: Yukyduky Date: Sun, 29 Oct 2023 10:08:29 +0100 Subject: [PATCH 05/10] Separated color_factor for button into text and background Tree node button background looked out of place when disabled, so I made the background not be affected by being disabled. --- demo/common/overview.c | 2 +- nuklear.h | 186 +++++++++++++++++++++++++---------------- src/nuklear.h | 3 +- src/nuklear_button.c | 22 ++--- src/nuklear_style.c | 69 ++++++++------- src/nuklear_widget.c | 92 +++++++++++++------- 6 files changed, 227 insertions(+), 147 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index c4f15f617..58221440e 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -180,6 +180,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); } @@ -259,7 +260,6 @@ overview(struct nk_context *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)) diff --git a/nuklear.h b/nuklear.h index cf703585a..ea69b00fa 100644 --- a/nuklear.h +++ b/nuklear.h @@ -4919,6 +4919,7 @@ struct nk_style_button { struct nk_style_item hover; struct nk_style_item active; struct nk_color border_color; + float color_factor_background; /* text */ struct nk_color text_background; @@ -4926,6 +4927,7 @@ struct nk_style_button { struct nk_color text_hover; struct nk_color text_active; nk_flags text_alignment; + float color_factor_text; /* properties */ float border; @@ -4933,7 +4935,6 @@ struct nk_style_button { struct nk_vec2 padding; struct nk_vec2 image_padding; struct nk_vec2 touch_padding; - float color_factor; float disabled_factor; /* optional user callbacks */ @@ -18288,25 +18289,26 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) /* default button */ button = &style->button; nk_zero_struct(*button); - button->normal = nk_style_item_color(table[NK_COLOR_BUTTON]); - button->hover = nk_style_item_color(table[NK_COLOR_BUTTON_HOVER]); - button->active = nk_style_item_color(table[NK_COLOR_BUTTON_ACTIVE]); - button->border_color = table[NK_COLOR_BORDER]; - button->text_background = table[NK_COLOR_BUTTON]; - button->text_normal = table[NK_COLOR_TEXT]; - button->text_hover = table[NK_COLOR_TEXT]; - button->text_active = table[NK_COLOR_TEXT]; - button->padding = nk_vec2(2.0f,2.0f); - button->image_padding = nk_vec2(0.0f,0.0f); - button->touch_padding = nk_vec2(0.0f, 0.0f); - button->userdata = nk_handle_ptr(0); - button->text_alignment = NK_TEXT_CENTERED; - button->border = 1.0f; - button->rounding = 4.0f; - button->color_factor = 1.0f; - button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; - button->draw_begin = 0; - button->draw_end = 0; + button->normal = nk_style_item_color(table[NK_COLOR_BUTTON]); + button->hover = nk_style_item_color(table[NK_COLOR_BUTTON_HOVER]); + button->active = nk_style_item_color(table[NK_COLOR_BUTTON_ACTIVE]); + button->border_color = table[NK_COLOR_BORDER]; + button->text_background = table[NK_COLOR_BUTTON]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(2.0f,2.0f); + button->image_padding = nk_vec2(0.0f,0.0f); + button->touch_padding = nk_vec2(0.0f, 0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 1.0f; + button->rounding = 4.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; + button->draw_begin = 0; + button->draw_end = 0; /* contextual button */ button = &style->contextual_button; @@ -18325,7 +18327,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18347,7 +18350,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 1.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18462,7 +18466,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18532,7 +18537,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18606,7 +18612,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18687,7 +18694,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18724,7 +18732,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18747,7 +18756,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18786,7 +18796,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -18808,7 +18819,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -23336,36 +23348,50 @@ nk_widget_disable_begin(struct nk_context* ctx) win->widgets_disabled = nk_true; - style->button.color_factor = style->button.disabled_factor; + style->button.color_factor_text = style->button.disabled_factor; + style->button.color_factor_background = style->button.disabled_factor; style->chart.color_factor = style->chart.disabled_factor; style->checkbox.color_factor = style->checkbox.disabled_factor; style->combo.color_factor = style->combo.disabled_factor; - style->combo.button.color_factor = style->combo.button.disabled_factor; - style->contextual_button.color_factor = style->contextual_button.disabled_factor; + style->combo.button.color_factor_text = style->combo.button.disabled_factor; + style->combo.button.color_factor_background = style->combo.button.disabled_factor; + style->contextual_button.color_factor_text = style->contextual_button.disabled_factor; + style->contextual_button.color_factor_background = style->contextual_button.disabled_factor; style->edit.color_factor = style->edit.disabled_factor; style->edit.scrollbar.color_factor = style->edit.scrollbar.disabled_factor; - style->menu_button.color_factor = style->menu_button.disabled_factor; + style->menu_button.color_factor_text = style->menu_button.disabled_factor; + style->menu_button.color_factor_background = style->menu_button.disabled_factor; style->option.color_factor = style->option.disabled_factor; style->progress.color_factor = style->progress.disabled_factor; style->property.color_factor = style->property.disabled_factor; - style->property.inc_button.color_factor = style->property.inc_button.disabled_factor; - style->property.dec_button.color_factor = style->property.dec_button.disabled_factor; + style->property.inc_button.color_factor_text = style->property.inc_button.disabled_factor; + style->property.inc_button.color_factor_background = style->property.inc_button.disabled_factor; + style->property.dec_button.color_factor_text = style->property.dec_button.disabled_factor; + style->property.dec_button.color_factor_background = style->property.dec_button.disabled_factor; style->property.edit.color_factor = style->property.edit.disabled_factor; style->scrollh.color_factor = style->scrollh.disabled_factor; - style->scrollh.inc_button.color_factor = style->scrollh.inc_button.disabled_factor; - style->scrollh.dec_button.color_factor = style->scrollh.dec_button.disabled_factor; + style->scrollh.inc_button.color_factor_text = style->scrollh.inc_button.disabled_factor; + style->scrollh.inc_button.color_factor_background = style->scrollh.inc_button.disabled_factor; + style->scrollh.dec_button.color_factor_text = style->scrollh.dec_button.disabled_factor; + style->scrollh.dec_button.color_factor_background = style->scrollh.dec_button.disabled_factor; style->scrollv.color_factor = style->scrollv.disabled_factor; - style->scrollv.inc_button.color_factor = style->scrollv.inc_button.disabled_factor; - style->scrollv.dec_button.color_factor = style->scrollv.dec_button.disabled_factor; + style->scrollv.inc_button.color_factor_text = style->scrollv.inc_button.disabled_factor; + style->scrollv.inc_button.color_factor_background = style->scrollv.inc_button.disabled_factor; + style->scrollv.dec_button.color_factor_text = style->scrollv.dec_button.disabled_factor; + style->scrollv.dec_button.color_factor_background = style->scrollv.dec_button.disabled_factor; style->selectable.color_factor = style->selectable.disabled_factor; style->slider.color_factor = style->slider.disabled_factor; - style->slider.inc_button.color_factor = style->slider.inc_button.disabled_factor; - style->slider.dec_button.color_factor = style->slider.dec_button.disabled_factor; + style->slider.inc_button.color_factor_text = style->slider.inc_button.disabled_factor; + style->slider.inc_button.color_factor_background = style->slider.inc_button.disabled_factor; + style->slider.dec_button.color_factor_text = style->slider.dec_button.disabled_factor; + style->slider.dec_button.color_factor_background = style->slider.dec_button.disabled_factor; style->tab.color_factor = style->tab.disabled_factor; - style->tab.node_maximize_button.color_factor = style->tab.node_maximize_button.disabled_factor; - style->tab.node_minimize_button.color_factor = style->tab.node_minimize_button.disabled_factor; - style->tab.tab_maximize_button.color_factor = style->tab.tab_maximize_button.disabled_factor; - style->tab.tab_minimize_button.color_factor = style->tab.tab_minimize_button.disabled_factor; + style->tab.node_maximize_button.color_factor_text = style->tab.node_maximize_button.disabled_factor; + style->tab.node_minimize_button.color_factor_text = style->tab.node_minimize_button.disabled_factor; + style->tab.tab_maximize_button.color_factor_text = style->tab.tab_maximize_button.disabled_factor; + style->tab.tab_maximize_button.color_factor_background = style->tab.tab_maximize_button.disabled_factor; + style->tab.tab_minimize_button.color_factor_text = style->tab.tab_minimize_button.disabled_factor; + style->tab.tab_minimize_button.color_factor_background = style->tab.tab_minimize_button.disabled_factor; style->text.color_factor = style->text.disabled_factor; } NK_API void @@ -23385,36 +23411,50 @@ nk_widget_disable_end(struct nk_context* ctx) win->widgets_disabled = nk_false; - style->button.color_factor = 1.0f; + style->button.color_factor_text = 1.0f; + style->button.color_factor_background = 1.0f; style->chart.color_factor = 1.0f; style->checkbox.color_factor = 1.0f; style->combo.color_factor = 1.0f; - style->combo.button.color_factor = 1.0f; - style->contextual_button.color_factor = 1.0f; + style->combo.button.color_factor_text = 1.0f; + style->combo.button.color_factor_background = 1.0f; + style->contextual_button.color_factor_text = 1.0f; + style->contextual_button.color_factor_background = 1.0f; style->edit.color_factor = 1.0f; style->edit.scrollbar.color_factor = 1.0f; - style->menu_button.color_factor = 1.0f; + style->menu_button.color_factor_text = 1.0f; + style->menu_button.color_factor_background = 1.0f; style->option.color_factor = 1.0f; style->progress.color_factor = 1.0f; style->property.color_factor = 1.0f; - style->property.inc_button.color_factor = 1.0f; - style->property.dec_button.color_factor = 1.0f; + style->property.inc_button.color_factor_text = 1.0f; + style->property.inc_button.color_factor_background = 1.0f; + style->property.dec_button.color_factor_text = 1.0f; + style->property.dec_button.color_factor_background = 1.0f; style->property.edit.color_factor = 1.0f; style->scrollh.color_factor = 1.0f; - style->scrollh.inc_button.color_factor = 1.0f; - style->scrollh.dec_button.color_factor = 1.0f; + style->scrollh.inc_button.color_factor_text = 1.0f; + style->scrollh.inc_button.color_factor_background = 1.0f; + style->scrollh.dec_button.color_factor_text = 1.0f; + style->scrollh.dec_button.color_factor_background = 1.0f; style->scrollv.color_factor = 1.0f; - style->scrollv.inc_button.color_factor = 1.0f; - style->scrollv.dec_button.color_factor = 1.0f; + style->scrollv.inc_button.color_factor_text = 1.0f; + style->scrollv.inc_button.color_factor_background = 1.0f; + style->scrollv.dec_button.color_factor_text = 1.0f; + style->scrollv.dec_button.color_factor_background = 1.0f; style->selectable.color_factor = 1.0f; style->slider.color_factor = 1.0f; - style->slider.inc_button.color_factor = 1.0f; - style->slider.dec_button.color_factor = 1.0f; + style->slider.inc_button.color_factor_text = 1.0f; + style->slider.inc_button.color_factor_background = 1.0f; + style->slider.dec_button.color_factor_text = 1.0f; + style->slider.dec_button.color_factor_background = 1.0f; style->tab.color_factor = 1.0f; - style->tab.node_maximize_button.color_factor = 1.0f; - style->tab.node_minimize_button.color_factor = 1.0f; - style->tab.tab_maximize_button.color_factor = 1.0f; - style->tab.tab_minimize_button.color_factor = 1.0f; + style->tab.node_maximize_button.color_factor_text = 1.0f; + style->tab.node_minimize_button.color_factor_text = 1.0f; + style->tab.tab_maximize_button.color_factor_text = 1.0f; + style->tab.tab_maximize_button.color_factor_background = 1.0f; + style->tab.tab_minimize_button.color_factor_text = 1.0f; + style->tab.tab_minimize_button.color_factor_background = 1.0f; style->text.color_factor = 1.0f; } @@ -24060,14 +24100,14 @@ nk_draw_button(struct nk_command_buffer *out, switch (background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor_background)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor_background)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); - nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor_background)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor_background)); break; } return background; @@ -24117,7 +24157,7 @@ nk_draw_button_text(struct nk_command_buffer *out, text.text = style->text_active; else text.text = style->text_normal; - text.text = nk_rgb_factor(text.text, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor_text); text.padding = nk_vec2(0,0); nk_widget_text(out, *content, txt, len, &text, text_alignment, font); @@ -24167,7 +24207,7 @@ nk_draw_button_symbol(struct nk_command_buffer *out, sym = style->text_active; else sym = style->text_normal; - sym = nk_rgb_factor(sym, style->color_factor); + sym = nk_rgb_factor(sym, style->color_factor_text); nk_draw_symbol(out, type, *content, bg, sym, 1, font); } NK_LIB nk_bool @@ -24199,7 +24239,7 @@ nk_draw_button_image(struct nk_command_buffer *out, nk_flags state, const struct nk_style_button *style, const struct nk_image *img) { nk_draw_button(out, bounds, state, style); - nk_draw_image(out, *content, img, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_image(out, *content, img, nk_rgb_factor(nk_white, style->color_factor_background)); } NK_LIB nk_bool nk_do_button_image(nk_flags *state, @@ -24256,8 +24296,8 @@ nk_draw_button_text_symbol(struct nk_command_buffer *out, text.text = style->text_normal; } - sym = nk_rgb_factor(sym, style->color_factor); - text.text = nk_rgb_factor(text.text, style->color_factor); + sym = nk_rgb_factor(sym, style->color_factor_text); + text.text = nk_rgb_factor(text.text, style->color_factor_text); text.padding = nk_vec2(0,0); nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font); nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); @@ -24315,10 +24355,10 @@ nk_draw_button_text_image(struct nk_command_buffer *out, text.text = style->text_active; else text.text = style->text_normal; - text.text = nk_rgb_factor(text.text, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor_text); text.padding = nk_vec2(0, 0); nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); - nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor_background)); } NK_LIB nk_bool nk_do_button_text_image(nk_flags *state, diff --git a/src/nuklear.h b/src/nuklear.h index a16607bb5..a7a024323 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -4697,6 +4697,7 @@ struct nk_style_button { struct nk_style_item hover; struct nk_style_item active; struct nk_color border_color; + float color_factor_background; /* text */ struct nk_color text_background; @@ -4704,6 +4705,7 @@ struct nk_style_button { struct nk_color text_hover; struct nk_color text_active; nk_flags text_alignment; + float color_factor_text; /* properties */ float border; @@ -4711,7 +4713,6 @@ struct nk_style_button { struct nk_vec2 padding; struct nk_vec2 image_padding; struct nk_vec2 touch_padding; - float color_factor; float disabled_factor; /* optional user callbacks */ diff --git a/src/nuklear_button.c b/src/nuklear_button.c index 423e0df1d..fca7f0ca4 100644 --- a/src/nuklear_button.c +++ b/src/nuklear_button.c @@ -100,14 +100,14 @@ nk_draw_button(struct nk_command_buffer *out, switch (background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor_background)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor_background)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); - nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); + nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor_background)); + nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor_background)); break; } return background; @@ -157,7 +157,7 @@ nk_draw_button_text(struct nk_command_buffer *out, text.text = style->text_active; else text.text = style->text_normal; - text.text = nk_rgb_factor(text.text, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor_text); text.padding = nk_vec2(0,0); nk_widget_text(out, *content, txt, len, &text, text_alignment, font); @@ -207,7 +207,7 @@ nk_draw_button_symbol(struct nk_command_buffer *out, sym = style->text_active; else sym = style->text_normal; - sym = nk_rgb_factor(sym, style->color_factor); + sym = nk_rgb_factor(sym, style->color_factor_text); nk_draw_symbol(out, type, *content, bg, sym, 1, font); } NK_LIB nk_bool @@ -239,7 +239,7 @@ nk_draw_button_image(struct nk_command_buffer *out, nk_flags state, const struct nk_style_button *style, const struct nk_image *img) { nk_draw_button(out, bounds, state, style); - nk_draw_image(out, *content, img, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_image(out, *content, img, nk_rgb_factor(nk_white, style->color_factor_background)); } NK_LIB nk_bool nk_do_button_image(nk_flags *state, @@ -296,8 +296,8 @@ nk_draw_button_text_symbol(struct nk_command_buffer *out, text.text = style->text_normal; } - sym = nk_rgb_factor(sym, style->color_factor); - text.text = nk_rgb_factor(text.text, style->color_factor); + sym = nk_rgb_factor(sym, style->color_factor_text); + text.text = nk_rgb_factor(text.text, style->color_factor_text); text.padding = nk_vec2(0,0); nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font); nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); @@ -355,10 +355,10 @@ nk_draw_button_text_image(struct nk_command_buffer *out, text.text = style->text_active; else text.text = style->text_normal; - text.text = nk_rgb_factor(text.text, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor_text); text.padding = nk_vec2(0, 0); nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); - nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor)); + nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor_background)); } NK_LIB nk_bool nk_do_button_text_image(nk_flags *state, diff --git a/src/nuklear_style.c b/src/nuklear_style.c index b97ad712e..6cf451433 100644 --- a/src/nuklear_style.c +++ b/src/nuklear_style.c @@ -119,25 +119,26 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) /* default button */ button = &style->button; nk_zero_struct(*button); - button->normal = nk_style_item_color(table[NK_COLOR_BUTTON]); - button->hover = nk_style_item_color(table[NK_COLOR_BUTTON_HOVER]); - button->active = nk_style_item_color(table[NK_COLOR_BUTTON_ACTIVE]); - button->border_color = table[NK_COLOR_BORDER]; - button->text_background = table[NK_COLOR_BUTTON]; - button->text_normal = table[NK_COLOR_TEXT]; - button->text_hover = table[NK_COLOR_TEXT]; - button->text_active = table[NK_COLOR_TEXT]; - button->padding = nk_vec2(2.0f,2.0f); - button->image_padding = nk_vec2(0.0f,0.0f); - button->touch_padding = nk_vec2(0.0f, 0.0f); - button->userdata = nk_handle_ptr(0); - button->text_alignment = NK_TEXT_CENTERED; - button->border = 1.0f; - button->rounding = 4.0f; - button->color_factor = 1.0f; - button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; - button->draw_begin = 0; - button->draw_end = 0; + button->normal = nk_style_item_color(table[NK_COLOR_BUTTON]); + button->hover = nk_style_item_color(table[NK_COLOR_BUTTON_HOVER]); + button->active = nk_style_item_color(table[NK_COLOR_BUTTON_ACTIVE]); + button->border_color = table[NK_COLOR_BORDER]; + button->text_background = table[NK_COLOR_BUTTON]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(2.0f,2.0f); + button->image_padding = nk_vec2(0.0f,0.0f); + button->touch_padding = nk_vec2(0.0f, 0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 1.0f; + button->rounding = 4.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; + button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; + button->draw_begin = 0; + button->draw_end = 0; /* contextual button */ button = &style->contextual_button; @@ -156,7 +157,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -178,7 +180,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 1.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -293,7 +296,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -363,7 +367,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 1.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -437,7 +442,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -518,7 +524,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -555,7 +562,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -578,7 +586,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -617,7 +626,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; @@ -639,7 +649,8 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->text_alignment = NK_TEXT_CENTERED; button->border = 0.0f; button->rounding = 0.0f; - button->color_factor = 1.0f; + button->color_factor_text = 1.0f; + button->color_factor_background = 1.0f; button->disabled_factor = NK_WIDGET_DISABLED_FACTOR; button->draw_begin = 0; button->draw_end = 0; diff --git a/src/nuklear_widget.c b/src/nuklear_widget.c index f2a243c04..a21f13721 100644 --- a/src/nuklear_widget.c +++ b/src/nuklear_widget.c @@ -246,36 +246,50 @@ nk_widget_disable_begin(struct nk_context* ctx) win->widgets_disabled = nk_true; - style->button.color_factor = style->button.disabled_factor; + style->button.color_factor_text = style->button.disabled_factor; + style->button.color_factor_background = style->button.disabled_factor; style->chart.color_factor = style->chart.disabled_factor; style->checkbox.color_factor = style->checkbox.disabled_factor; style->combo.color_factor = style->combo.disabled_factor; - style->combo.button.color_factor = style->combo.button.disabled_factor; - style->contextual_button.color_factor = style->contextual_button.disabled_factor; + style->combo.button.color_factor_text = style->combo.button.disabled_factor; + style->combo.button.color_factor_background = style->combo.button.disabled_factor; + style->contextual_button.color_factor_text = style->contextual_button.disabled_factor; + style->contextual_button.color_factor_background = style->contextual_button.disabled_factor; style->edit.color_factor = style->edit.disabled_factor; style->edit.scrollbar.color_factor = style->edit.scrollbar.disabled_factor; - style->menu_button.color_factor = style->menu_button.disabled_factor; + style->menu_button.color_factor_text = style->menu_button.disabled_factor; + style->menu_button.color_factor_background = style->menu_button.disabled_factor; style->option.color_factor = style->option.disabled_factor; style->progress.color_factor = style->progress.disabled_factor; style->property.color_factor = style->property.disabled_factor; - style->property.inc_button.color_factor = style->property.inc_button.disabled_factor; - style->property.dec_button.color_factor = style->property.dec_button.disabled_factor; + style->property.inc_button.color_factor_text = style->property.inc_button.disabled_factor; + style->property.inc_button.color_factor_background = style->property.inc_button.disabled_factor; + style->property.dec_button.color_factor_text = style->property.dec_button.disabled_factor; + style->property.dec_button.color_factor_background = style->property.dec_button.disabled_factor; style->property.edit.color_factor = style->property.edit.disabled_factor; style->scrollh.color_factor = style->scrollh.disabled_factor; - style->scrollh.inc_button.color_factor = style->scrollh.inc_button.disabled_factor; - style->scrollh.dec_button.color_factor = style->scrollh.dec_button.disabled_factor; + style->scrollh.inc_button.color_factor_text = style->scrollh.inc_button.disabled_factor; + style->scrollh.inc_button.color_factor_background = style->scrollh.inc_button.disabled_factor; + style->scrollh.dec_button.color_factor_text = style->scrollh.dec_button.disabled_factor; + style->scrollh.dec_button.color_factor_background = style->scrollh.dec_button.disabled_factor; style->scrollv.color_factor = style->scrollv.disabled_factor; - style->scrollv.inc_button.color_factor = style->scrollv.inc_button.disabled_factor; - style->scrollv.dec_button.color_factor = style->scrollv.dec_button.disabled_factor; + style->scrollv.inc_button.color_factor_text = style->scrollv.inc_button.disabled_factor; + style->scrollv.inc_button.color_factor_background = style->scrollv.inc_button.disabled_factor; + style->scrollv.dec_button.color_factor_text = style->scrollv.dec_button.disabled_factor; + style->scrollv.dec_button.color_factor_background = style->scrollv.dec_button.disabled_factor; style->selectable.color_factor = style->selectable.disabled_factor; style->slider.color_factor = style->slider.disabled_factor; - style->slider.inc_button.color_factor = style->slider.inc_button.disabled_factor; - style->slider.dec_button.color_factor = style->slider.dec_button.disabled_factor; + style->slider.inc_button.color_factor_text = style->slider.inc_button.disabled_factor; + style->slider.inc_button.color_factor_background = style->slider.inc_button.disabled_factor; + style->slider.dec_button.color_factor_text = style->slider.dec_button.disabled_factor; + style->slider.dec_button.color_factor_background = style->slider.dec_button.disabled_factor; style->tab.color_factor = style->tab.disabled_factor; - style->tab.node_maximize_button.color_factor = style->tab.node_maximize_button.disabled_factor; - style->tab.node_minimize_button.color_factor = style->tab.node_minimize_button.disabled_factor; - style->tab.tab_maximize_button.color_factor = style->tab.tab_maximize_button.disabled_factor; - style->tab.tab_minimize_button.color_factor = style->tab.tab_minimize_button.disabled_factor; + style->tab.node_maximize_button.color_factor_text = style->tab.node_maximize_button.disabled_factor; + style->tab.node_minimize_button.color_factor_text = style->tab.node_minimize_button.disabled_factor; + style->tab.tab_maximize_button.color_factor_text = style->tab.tab_maximize_button.disabled_factor; + style->tab.tab_maximize_button.color_factor_background = style->tab.tab_maximize_button.disabled_factor; + style->tab.tab_minimize_button.color_factor_text = style->tab.tab_minimize_button.disabled_factor; + style->tab.tab_minimize_button.color_factor_background = style->tab.tab_minimize_button.disabled_factor; style->text.color_factor = style->text.disabled_factor; } NK_API void @@ -295,35 +309,49 @@ nk_widget_disable_end(struct nk_context* ctx) win->widgets_disabled = nk_false; - style->button.color_factor = 1.0f; + style->button.color_factor_text = 1.0f; + style->button.color_factor_background = 1.0f; style->chart.color_factor = 1.0f; style->checkbox.color_factor = 1.0f; style->combo.color_factor = 1.0f; - style->combo.button.color_factor = 1.0f; - style->contextual_button.color_factor = 1.0f; + style->combo.button.color_factor_text = 1.0f; + style->combo.button.color_factor_background = 1.0f; + style->contextual_button.color_factor_text = 1.0f; + style->contextual_button.color_factor_background = 1.0f; style->edit.color_factor = 1.0f; style->edit.scrollbar.color_factor = 1.0f; - style->menu_button.color_factor = 1.0f; + style->menu_button.color_factor_text = 1.0f; + style->menu_button.color_factor_background = 1.0f; style->option.color_factor = 1.0f; style->progress.color_factor = 1.0f; style->property.color_factor = 1.0f; - style->property.inc_button.color_factor = 1.0f; - style->property.dec_button.color_factor = 1.0f; + style->property.inc_button.color_factor_text = 1.0f; + style->property.inc_button.color_factor_background = 1.0f; + style->property.dec_button.color_factor_text = 1.0f; + style->property.dec_button.color_factor_background = 1.0f; style->property.edit.color_factor = 1.0f; style->scrollh.color_factor = 1.0f; - style->scrollh.inc_button.color_factor = 1.0f; - style->scrollh.dec_button.color_factor = 1.0f; + style->scrollh.inc_button.color_factor_text = 1.0f; + style->scrollh.inc_button.color_factor_background = 1.0f; + style->scrollh.dec_button.color_factor_text = 1.0f; + style->scrollh.dec_button.color_factor_background = 1.0f; style->scrollv.color_factor = 1.0f; - style->scrollv.inc_button.color_factor = 1.0f; - style->scrollv.dec_button.color_factor = 1.0f; + style->scrollv.inc_button.color_factor_text = 1.0f; + style->scrollv.inc_button.color_factor_background = 1.0f; + style->scrollv.dec_button.color_factor_text = 1.0f; + style->scrollv.dec_button.color_factor_background = 1.0f; style->selectable.color_factor = 1.0f; style->slider.color_factor = 1.0f; - style->slider.inc_button.color_factor = 1.0f; - style->slider.dec_button.color_factor = 1.0f; + style->slider.inc_button.color_factor_text = 1.0f; + style->slider.inc_button.color_factor_background = 1.0f; + style->slider.dec_button.color_factor_text = 1.0f; + style->slider.dec_button.color_factor_background = 1.0f; style->tab.color_factor = 1.0f; - style->tab.node_maximize_button.color_factor = 1.0f; - style->tab.node_minimize_button.color_factor = 1.0f; - style->tab.tab_maximize_button.color_factor = 1.0f; - style->tab.tab_minimize_button.color_factor = 1.0f; + style->tab.node_maximize_button.color_factor_text = 1.0f; + style->tab.node_minimize_button.color_factor_text = 1.0f; + style->tab.tab_maximize_button.color_factor_text = 1.0f; + style->tab.tab_maximize_button.color_factor_background = 1.0f; + style->tab.tab_minimize_button.color_factor_text = 1.0f; + style->tab.tab_minimize_button.color_factor_background = 1.0f; style->text.color_factor = 1.0f; } From f88d7b58bb944b0bbedcc4bd7799ca3ed714c28a Mon Sep 17 00:00:00 2001 From: Yukyduky Date: Sun, 29 Oct 2023 10:18:09 +0100 Subject: [PATCH 06/10] Fixed tabs not being shown as disabled properly --- nuklear.h | 10 +++++----- src/nuklear_tree.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nuklear.h b/nuklear.h index ea69b00fa..580026a92 100644 --- a/nuklear.h +++ b/nuklear.h @@ -22483,15 +22483,15 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, header, &background->data.image, nk_white); + nk_draw_image(out, header, &background->data.image, nk_rgb_factor(nk_white, style->tab.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, header, &background->data.slice, nk_white); + nk_draw_nine_slice(out, header, &background->data.slice, nk_rgb_factor(nk_white, style->tab.color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, header, 0, style->tab.border_color); + nk_fill_rect(out, header, 0, nk_rgb_factor(style->tab.border_color, style->tab.color_factor)); nk_fill_rect(out, nk_shrink_rect(header, style->tab.border), - style->tab.rounding, background->data.color); + style->tab.rounding, nk_rgb_factor(background->data.color, style->tab.color_factor)); break; } } else text.background = style->window.background; @@ -22536,7 +22536,7 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, label.y = sym.y; label.w = header.w - (sym.w + item_spacing.y + style->tab.indent); label.h = style->font->height; - text.text = style->tab.text; + text.text = nk_rgb_factor(style->tab.text, style->tab.color_factor); text.padding = nk_vec2(0,0); nk_widget_text(out, label, title, nk_strlen(title), &text, NK_TEXT_LEFT, style->font);} diff --git a/src/nuklear_tree.c b/src/nuklear_tree.c index ef37ff031..8ecc8c3a1 100644 --- a/src/nuklear_tree.c +++ b/src/nuklear_tree.c @@ -52,15 +52,15 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, switch(background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, header, &background->data.image, nk_white); + nk_draw_image(out, header, &background->data.image, nk_rgb_factor(nk_white, style->tab.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, header, &background->data.slice, nk_white); + nk_draw_nine_slice(out, header, &background->data.slice, nk_rgb_factor(nk_white, style->tab.color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, header, 0, style->tab.border_color); + nk_fill_rect(out, header, 0, nk_rgb_factor(style->tab.border_color, style->tab.color_factor)); nk_fill_rect(out, nk_shrink_rect(header, style->tab.border), - style->tab.rounding, background->data.color); + style->tab.rounding, nk_rgb_factor(background->data.color, style->tab.color_factor)); break; } } else text.background = style->window.background; @@ -105,7 +105,7 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, label.y = sym.y; label.w = header.w - (sym.w + item_spacing.y + style->tab.indent); label.h = style->font->height; - text.text = style->tab.text; + text.text = nk_rgb_factor(style->tab.text, style->tab.color_factor); text.padding = nk_vec2(0,0); nk_widget_text(out, label, title, nk_strlen(title), &text, NK_TEXT_LEFT, style->font);} From df13a41ada98e6204e40c8d372d5f5567c201515 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Mon, 20 Nov 2023 13:56:19 +0100 Subject: [PATCH 07/10] Fixed C90 compliance issue --- nuklear.h | 6 +++--- src/nuklear_edit.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nuklear.h b/nuklear.h index 314daa410..5c451456f 100644 --- a/nuklear.h +++ b/nuklear.h @@ -27190,14 +27190,14 @@ 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; txt.padding = nk_vec2(0,0); txt.background = background; txt.text = foreground; + foreground = nk_rgb_factor(foreground, style->color_factor); + background = nk_rgb_factor(background, style->color_factor); + glyph_len = nk_utf_decode(text+text_len, &unicode, byte_len-text_len); if (!glyph_len) return; while ((text_len < byte_len) && glyph_len) diff --git a/src/nuklear_edit.c b/src/nuklear_edit.c index 4157dd8e0..a7b2bfcf1 100644 --- a/src/nuklear_edit.c +++ b/src/nuklear_edit.c @@ -89,14 +89,14 @@ 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; txt.padding = nk_vec2(0,0); txt.background = background; txt.text = foreground; + foreground = nk_rgb_factor(foreground, style->color_factor); + background = nk_rgb_factor(background, style->color_factor); + glyph_len = nk_utf_decode(text+text_len, &unicode, byte_len-text_len); if (!glyph_len) return; while ((text_len < byte_len) && glyph_len) From 304856e71eba639a1e1088a07da9409ac61658e8 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Mon, 20 Nov 2023 13:57:45 +0100 Subject: [PATCH 08/10] Made disable widget example run on more types of widgets --- demo/common/overview.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/demo/common/overview.c b/demo/common/overview.c index 58221440e..02b69bd2f 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -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); @@ -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 */ @@ -1283,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"); From afbd13391495efce07000998394df035ef1c2387 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Mon, 20 Nov 2023 14:01:22 +0100 Subject: [PATCH 09/10] Fixed missing color factoring for widget disabling --- nuklear.h | 9 +++++---- src/nuklear_tree.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/nuklear.h b/nuklear.h index 5c451456f..88ecccf6a 100644 --- a/nuklear.h +++ b/nuklear.h @@ -22673,15 +22673,16 @@ nk_tree_element_image_push_hashed_base(struct nk_context *ctx, enum nk_tree_type switch (background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, header, &background->data.image, nk_white); + nk_draw_image(out, header, &background->data.image, nk_rgb_factor(nk_white, style->tab.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, header, &background->data.slice, nk_white); + nk_draw_nine_slice(out, header, &background->data.slice, nk_rgb_factor(nk_white, style->tab.color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, header, 0, style->tab.border_color); + nk_fill_rect(out, header, 0, nk_rgb_factor(style->tab.border_color, style->tab.color_factor)); nk_fill_rect(out, nk_shrink_rect(header, style->tab.border), - style->tab.rounding, background->data.color); + style->tab.rounding, nk_rgb_factor(background->data.color, style->tab.color_factor)); + break; } } diff --git a/src/nuklear_tree.c b/src/nuklear_tree.c index 8ecc8c3a1..0ccf68ecb 100644 --- a/src/nuklear_tree.c +++ b/src/nuklear_tree.c @@ -242,15 +242,16 @@ nk_tree_element_image_push_hashed_base(struct nk_context *ctx, enum nk_tree_type switch (background->type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, header, &background->data.image, nk_white); + nk_draw_image(out, header, &background->data.image, nk_rgb_factor(nk_white, style->tab.color_factor)); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, header, &background->data.slice, nk_white); + nk_draw_nine_slice(out, header, &background->data.slice, nk_rgb_factor(nk_white, style->tab.color_factor)); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, header, 0, style->tab.border_color); + nk_fill_rect(out, header, 0, nk_rgb_factor(style->tab.border_color, style->tab.color_factor)); nk_fill_rect(out, nk_shrink_rect(header, style->tab.border), - style->tab.rounding, background->data.color); + style->tab.rounding, nk_rgb_factor(background->data.color, style->tab.color_factor)); + break; } } From 39e2ee3ce4ccaef3f41319028261c23780eae7ac Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Mon, 20 Nov 2023 14:02:12 +0100 Subject: [PATCH 10/10] Removed color factoring for item colored selectables --- nuklear.h | 2 +- src/nuklear_selectable.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nuklear.h b/nuklear.h index 88ecccf6a..583dc03d6 100644 --- a/nuklear.h +++ b/nuklear.h @@ -25062,7 +25062,7 @@ nk_draw_selectable(struct nk_command_buffer *out, break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_fill_rect(out, *bounds, style->rounding, background->data.color); break; } if (icon) { diff --git a/src/nuklear_selectable.c b/src/nuklear_selectable.c index 3f4bfc4b1..1b8c0b2ea 100644 --- a/src/nuklear_selectable.c +++ b/src/nuklear_selectable.c @@ -56,7 +56,7 @@ nk_draw_selectable(struct nk_command_buffer *out, break; case NK_STYLE_ITEM_COLOR: text.background = background->data.color; - nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); + nk_fill_rect(out, *bounds, style->rounding, background->data.color); break; } if (icon) {