From 8066c09df2546f8cf9d4356ec7b3f9108e7b59a2 Mon Sep 17 00:00:00 2001 From: Lukas Toenne Date: Thu, 21 Mar 2013 12:58:31 +0000 Subject: [PATCH] Fix for extra string width padding in ui_text_icon_width, causing labels in right-aligned layouts show an annoying gap. If the layout is right-aligned, make the text button align right as well, so text is drawn at the right side of the alloted rect. --- source/blender/editors/interface/interface_layout.c | 8 ++++++++ source/blender/editors/interface/interface_widgets.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 5b6e432fc61..53887163778 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1599,6 +1599,14 @@ static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon) else but = uiDefBut(block, LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + /* to compensate for string size padding in ui_text_icon_width, + * make text aligned right if the layout is aligned right. + */ + if (uiLayoutGetAlignment(layout) == UI_LAYOUT_ALIGN_RIGHT) { + but->flag &= ~UI_TEXT_LEFT; /* default, needs to be unset */ + but->flag |= UI_TEXT_RIGHT; + } + return but; } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index f2e553bd140..c5d97cb7cd9 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1147,6 +1147,8 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b if (but->editstr || (but->flag & UI_TEXT_LEFT)) fstyle->align = UI_STYLE_TEXT_LEFT; + else if (but->flag & UI_TEXT_RIGHT) + fstyle->align = UI_STYLE_TEXT_RIGHT; else fstyle->align = UI_STYLE_TEXT_CENTER; @@ -1333,10 +1335,16 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB if (but->editstr || (but->flag & UI_TEXT_LEFT)) { rect->xmin += (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; } + else if ((but->flag & UI_TEXT_RIGHT)) { + rect->xmax -= (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; + } } else if ((but->flag & UI_TEXT_LEFT)) { rect->xmin += (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; } + else if ((but->flag & UI_TEXT_RIGHT)) { + rect->xmax -= (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; + } /* unlink icon for this button type */ if (but->type == SEARCH_MENU_UNLINK && but->drawstr[0]) {