diff --git a/demo/common/overview.c b/demo/common/overview.c index 5ce339ff2..7c783ad57 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -214,8 +214,12 @@ overview(struct nk_context *ctx) nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE); nk_layout_row_static(ctx, 30, 100, 2); + nk_style_push_flags(ctx, &ctx->style.button.text_alignment, NK_TEXT_LEFT); nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_LEFT, "prev", NK_TEXT_RIGHT); + nk_style_pop_flags(ctx); + nk_style_push_flags(ctx, &ctx->style.button.text_alignment, NK_TEXT_RIGHT); nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_RIGHT, "next", NK_TEXT_LEFT); + nk_style_pop_flags(ctx); nk_tree_pop(ctx); } diff --git a/nuklear.h b/nuklear.h index 19553b418..163f66bb9 100644 --- a/nuklear.h +++ b/nuklear.h @@ -24475,7 +24475,7 @@ nk_draw_button_text_symbol(struct nk_command_buffer *out, 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); + nk_widget_text(out, *label, str, len, &text, style->text_alignment, font); } NK_LIB nk_bool nk_do_button_text_symbol(nk_flags *state, @@ -24487,6 +24487,7 @@ nk_do_button_text_symbol(nk_flags *state, int ret; struct nk_rect tri = {0,0,0,0}; struct nk_rect content; + float label_icon_spacing = 0.f; NK_ASSERT(style); NK_ASSERT(out); @@ -24500,7 +24501,20 @@ nk_do_button_text_symbol(nk_flags *state, if (align & NK_TEXT_ALIGN_LEFT) { tri.x = (content.x + content.w) - (2 * style->padding.x + tri.w); tri.x = NK_MAX(tri.x, 0); - } else tri.x = content.x + 2 * style->padding.x; + + label_icon_spacing = ((bounds.x + bounds.w) - (tri.x + tri.w)) * 0.5f; + /*label_icon_spacing = ((content.x + content.w) - (tri.x + tri.w)) * 1.f;*/ + content.w = tri.x - content.x - label_icon_spacing; + content.w = NK_MAX(content.w, 0); + } else { + tri.x = content.x + 2 * style->padding.x; + + label_icon_spacing = (tri.x - bounds.x) * 0.5f; + /*label_icon_spacing = (tri.x - content.x) * 1.f;*/ + content.x = tri.x + tri.w + label_icon_spacing; + content.w -= tri.w + label_icon_spacing; + content.w = NK_MAX(content.w, 0); + } /* draw button */ if (style->draw_begin) style->draw_begin(out, style->userdata); @@ -24532,7 +24546,7 @@ nk_draw_button_text_image(struct nk_command_buffer *out, 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_widget_text(out, *label, str, len, &text, style->text_alignment, font); nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor_background)); } NK_LIB nk_bool @@ -24545,6 +24559,7 @@ nk_do_button_text_image(nk_flags *state, int ret; struct nk_rect icon; struct nk_rect content; + float label_icon_spacing = 0.f; NK_ASSERT(style); NK_ASSERT(state); @@ -24557,9 +24572,22 @@ nk_do_button_text_image(nk_flags *state, icon.y = bounds.y + style->padding.y; icon.w = icon.h = bounds.h - 2 * style->padding.y; if (align & NK_TEXT_ALIGN_LEFT) { - icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w); + icon.x = (content.x + content.w) - (2 * style->padding.x + icon.w); icon.x = NK_MAX(icon.x, 0); - } else icon.x = bounds.x + 2 * style->padding.x; + + label_icon_spacing = ((bounds.x + bounds.w) - (icon.x + icon.w)) * 0.5f; + /*label_icon_spacing = ((content.x + content.w) - (icon.x + icon.w)) * 1.f;*/ + content.w = icon.x - content.x - label_icon_spacing; + content.w = NK_MAX(content.w, 0); + } else { + icon.x = content.x + 2 * style->padding.x; + + label_icon_spacing = (icon.x - bounds.x) * 0.5f; + /*label_icon_spacing = (icon.x - content.x) * 1.f;*/ + content.x = icon.x + icon.w + label_icon_spacing; + content.w -= icon.w + label_icon_spacing; + content.w = NK_MAX(content.w, 0); + } icon.x += style->image_padding.x; icon.y += style->image_padding.y; diff --git a/src/nuklear_button.c b/src/nuklear_button.c index 6ef845997..7e076ebf2 100644 --- a/src/nuklear_button.c +++ b/src/nuklear_button.c @@ -313,7 +313,7 @@ nk_draw_button_text_symbol(struct nk_command_buffer *out, 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); + nk_widget_text(out, *label, str, len, &text, style->text_alignment, font); } NK_LIB nk_bool nk_do_button_text_symbol(nk_flags *state, @@ -325,6 +325,7 @@ nk_do_button_text_symbol(nk_flags *state, int ret; struct nk_rect tri = {0,0,0,0}; struct nk_rect content; + float label_icon_spacing = 0.f; NK_ASSERT(style); NK_ASSERT(out); @@ -338,7 +339,20 @@ nk_do_button_text_symbol(nk_flags *state, if (align & NK_TEXT_ALIGN_LEFT) { tri.x = (content.x + content.w) - (2 * style->padding.x + tri.w); tri.x = NK_MAX(tri.x, 0); - } else tri.x = content.x + 2 * style->padding.x; + + label_icon_spacing = ((bounds.x + bounds.w) - (tri.x + tri.w)) * 0.5f; + /*label_icon_spacing = ((content.x + content.w) - (tri.x + tri.w)) * 1.f;*/ + content.w = tri.x - content.x - label_icon_spacing; + content.w = NK_MAX(content.w, 0); + } else { + tri.x = content.x + 2 * style->padding.x; + + label_icon_spacing = (tri.x - bounds.x) * 0.5f; + /*label_icon_spacing = (tri.x - content.x) * 1.f;*/ + content.x = tri.x + tri.w + label_icon_spacing; + content.w -= tri.w + label_icon_spacing; + content.w = NK_MAX(content.w, 0); + } /* draw button */ if (style->draw_begin) style->draw_begin(out, style->userdata); @@ -370,7 +384,7 @@ nk_draw_button_text_image(struct nk_command_buffer *out, 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_widget_text(out, *label, str, len, &text, style->text_alignment, font); nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor_background)); } NK_LIB nk_bool @@ -383,6 +397,7 @@ nk_do_button_text_image(nk_flags *state, int ret; struct nk_rect icon; struct nk_rect content; + float label_icon_spacing = 0.f; NK_ASSERT(style); NK_ASSERT(state); @@ -395,9 +410,20 @@ nk_do_button_text_image(nk_flags *state, icon.y = bounds.y + style->padding.y; icon.w = icon.h = bounds.h - 2 * style->padding.y; if (align & NK_TEXT_ALIGN_LEFT) { - icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w); + icon.x = (content.x + content.w) - (2 * style->padding.x + icon.w); icon.x = NK_MAX(icon.x, 0); - } else icon.x = bounds.x + 2 * style->padding.x; + + label_icon_spacing = ((bounds.x + bounds.w) - (icon.x + icon.w)) * 0.5f; + content.w = icon.x - content.x - label_icon_spacing; + content.w = NK_MAX(content.w, 0); + } else { + icon.x = content.x + 2 * style->padding.x; + + label_icon_spacing = (icon.x - bounds.x) * 0.5f; + content.x = icon.x + icon.w + label_icon_spacing; + content.w -= icon.w + label_icon_spacing; + content.w = NK_MAX(content.w, 0); + } icon.x += style->image_padding.x; icon.y += style->image_padding.y;