From c32d5d7150c3a58271e8efff894b62e99541e690 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Tue, 10 Mar 2020 21:23:58 -0700 Subject: [PATCH] Added additional button text alignments --- demo/style_configurator.c | 63 +++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/demo/style_configurator.c b/demo/style_configurator.c index c0c302a45..b6023795c 100644 --- a/demo/style_configurator.c +++ b/demo/style_configurator.c @@ -143,31 +143,45 @@ style_button(struct nk_context* ctx, struct nk_style_button* out_style, struct n style_vec2(ctx, "Image Padding:", &button.image_padding); style_vec2(ctx, "Touch Padding:", &button.touch_padding); - /* -enum nk_text_align { -NK_TEXT_ALIGN_LEFT = 0x01, -NK_TEXT_ALIGN_CENTERED = 0x02, -NK_TEXT_ALIGN_RIGHT = 0x04, -NK_TEXT_ALIGN_TOP = 0x08, -NK_TEXT_ALIGN_MIDDLE = 0x10, -NK_TEXT_ALIGN_BOTTOM = 0x20 + const char* alignments[] = +{ + "LEFT", + "CENTERED", + "RIGHT", + "TOP LEFT", + "TOP CENTERED", + "TOP_RIGHT", + "BOTTOM LEFT", + "BOTTOM CENTERED", + "BOTTOM RIGHT" }; -enum nk_text_alignment { -NK_TEXT_LEFT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_LEFT, -NK_TEXT_CENTERED = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_CENTERED, -NK_TEXT_RIGHT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_RIGHT + +#define TOP_LEFT NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_LEFT +#define TOP_CENTER NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_CENTERED +#define TOP_RIGHT NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_RIGHT +#define BOTTOM_LEFT NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_LEFT +#define BOTTOM_CENTER NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_CENTERED +#define BOTTOM_RIGHT NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_RIGHT + + int aligns[] = +{ + NK_TEXT_LEFT, + NK_TEXT_CENTERED, + NK_TEXT_RIGHT, + TOP_LEFT, + TOP_CENTER, + TOP_RIGHT, + BOTTOM_LEFT, + BOTTOM_CENTER, + BOTTOM_RIGHT }; -*/ - // TODO support combining with TOP/MIDDLE/BOTTOM .. separate combo? - const char* alignments[] = { "LEFT", "CENTERED", "RIGHT" }; - int aligns[3] = { NK_TEXT_LEFT, NK_TEXT_CENTERED, NK_TEXT_RIGHT }; + int cur_align; - if (button.text_alignment == NK_TEXT_LEFT) { - cur_align = 0; - } else if (button.text_alignment == NK_TEXT_CENTERED) { - cur_align = 1; - } else { - cur_align = 2; + for (int i=0; istyle.scrollh.dec_button, &ctx->style.scrollv.inc_button, &ctx->style.scrollv.dec_button }; @@ -407,9 +420,6 @@ style_edit(struct nk_context* ctx, struct nk_style_edit* out_style) style_vec2(ctx, "Scrollbar Size:", &edit.scrollbar_size); style_vec2(ctx, "Padding:", &edit.padding); - // TODO subtree? - //edit->scrollbar = style->scrollv; - nk_property_float(ctx, "#Row Padding:", -100.0f, &edit.row_padding, 100.0f, 1,0.5f); nk_property_float(ctx, "#Cursor Size:", -100.0f, &edit.cursor_size, 100.0f, 1,0.5f); nk_property_float(ctx, "#Border:", -100.0f, &edit.border, 100.0f, 1,0.5f); @@ -572,6 +582,7 @@ style_window_header(struct nk_context* ctx, struct nk_style_window_header* out_s nk_layout_row_dynamic(ctx, 30, 2); nk_label(ctx, "Button Alignment:", NK_TEXT_LEFT); header.align = nk_combo(ctx, alignments, NUM_ALIGNS, header.align, 25, nk_vec2(200,200)); +#undef NUM_ALIGNS nk_label(ctx, "Close Symbol:", NK_TEXT_LEFT); header.close_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, header.close_symbol, 25, nk_vec2(200,200));