From 37e54da201cc5aad78ebcf621f6dc161407f4713 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 28 Apr 2024 02:42:54 -0400 Subject: [PATCH] property: Allow optional labels for properties with # (#634) --- demo/common/overview.c | 5 +++++ nuklear.h | 10 +++++++--- src/nuklear_property.c | 10 +++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index 69440c8b5..c6aaf4e2a 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -233,6 +233,7 @@ overview(struct nk_context *ctx) static int range_int_value = 2048; static int range_int_max = 4096; static const float ratio[] = {120, 150}; + static int range_int_value_hidden = 2048; nk_layout_row_dynamic(ctx, 0, 1); nk_checkbox_label(ctx, "CheckLeft TextLeft", &checkbox_left_text_left); @@ -278,6 +279,10 @@ overview(struct nk_context *ctx) nk_property_int(ctx, "#neg:", range_int_min, &range_int_value, range_int_max, 1, 10); nk_property_int(ctx, "#max:", range_int_min, &range_int_max, INT_MAX, 1, 10); + nk_layout_row_dynamic(ctx, 0, 2); + nk_label(ctx, "Hidden Label:", NK_TEXT_LEFT); + nk_property_int(ctx, "##Hidden Label", range_int_min, &range_int_value_hidden, INT_MAX, 1, 10); + nk_tree_pop(ctx); } diff --git a/nuklear.h b/nuklear.h index 29d2763c9..784880b9c 100644 --- a/nuklear.h +++ b/nuklear.h @@ -28180,7 +28180,9 @@ nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property * /* draw label */ text.padding = nk_vec2(0,0); - nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font); + if (name && name[0] != '#') { + nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font); + } } NK_LIB void nk_do_property(nk_flags *ws, @@ -28198,7 +28200,7 @@ nk_do_property(nk_flags *ws, nk_filter_float }; nk_bool active, old; - int num_len = 0, name_len; + int num_len = 0, name_len = 0; char string[NK_MAX_NUMBER_BUFFER]; float size; @@ -28218,7 +28220,9 @@ nk_do_property(nk_flags *ws, left.y = property.y + style->border + property.h/2.0f - left.h/2; /* text label */ - name_len = nk_strlen(name); + if (name && name[0] != '#') { + name_len = nk_strlen(name); + } size = font->width(font->userdata, font->height, name, name_len); label.x = left.x + left.w + style->padding.x; label.w = (float)size + 2 * style->padding.x; diff --git a/src/nuklear_property.c b/src/nuklear_property.c index fb76d67a8..4386b0dd1 100644 --- a/src/nuklear_property.c +++ b/src/nuklear_property.c @@ -106,7 +106,9 @@ nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property * /* draw label */ text.padding = nk_vec2(0,0); - nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font); + if (name && name[0] != '#') { + nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font); + } } NK_LIB void nk_do_property(nk_flags *ws, @@ -124,7 +126,7 @@ nk_do_property(nk_flags *ws, nk_filter_float }; nk_bool active, old; - int num_len = 0, name_len; + int num_len = 0, name_len = 0; char string[NK_MAX_NUMBER_BUFFER]; float size; @@ -144,7 +146,9 @@ nk_do_property(nk_flags *ws, left.y = property.y + style->border + property.h/2.0f - left.h/2; /* text label */ - name_len = nk_strlen(name); + if (name && name[0] != '#') { + name_len = nk_strlen(name); + } size = font->width(font->userdata, font->height, name, name_len); label.x = left.x + left.w + style->padding.x; label.w = (float)size + 2 * style->padding.x;