From dde5e5ce2581ffd544b442c58d6eefbc1ff61772 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 11 Dec 2013 21:27:13 +1100 Subject: User Interface: Align number buttons labels to the left, number right --- source/blender/blenkernel/intern/unit.c | 3 ++- source/blender/editors/interface/interface.c | 5 ++++ .../blender/editors/interface/interface_intern.h | 3 +++ .../blender/editors/interface/interface_widgets.c | 28 +++++++++++++++++++--- 4 files changed, 35 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index 8e92f86502e..17aad7a5a2c 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -392,7 +392,7 @@ static int unit_as_string(char *str, int len_max, double value, int prec, bUnitC while (unit->name_short[j] && (i < len_max)) { str[i++] = unit->name_short[j++]; } - +#if 0 if (pad) { /* this loop only runs if so many zeros were removed that * the unit name only used padded chars, @@ -402,6 +402,7 @@ static int unit_as_string(char *str, int len_max, double value, int prec, bUnitC str[i++] = pad; } } +#endif } /* terminate no matter whats done with padding above */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 79db94e5da8..aaaf64ba86e 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2867,6 +2867,11 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, { but->drawflag |= (UI_BUT_TEXT_LEFT | UI_BUT_ICON_LEFT); } +#ifdef USE_NUMBUTS_LR_ALIGN + else if (ELEM(but->type, NUM, NUMSLI)) { + but->drawflag |= UI_BUT_TEXT_LEFT; + } +#endif but->drawflag |= (block->flag & UI_BUT_ALIGN); diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 3ef7117ffdb..cbc1cd2cbbd 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -148,6 +148,9 @@ enum { /* bit-row */ #define UI_BITBUT_ROW(min, max) (((max) >= 31 ? 0xFFFFFFFF : (1 << (max + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) ) +/* split numbuts by ':' and align l/r */ +#define USE_NUMBUTS_LR_ALIGN + typedef struct uiLinkLine { /* only for draw/edit */ struct uiLinkLine *next, *prev; struct uiBut *from, *to; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index d353983ff70..9826f07e464 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1124,6 +1124,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b { int drawstr_left_len = UI_MAX_DRAW_STR; char *drawstr_right = NULL; + bool use_right_only = false; /* for underline drawing */ float font_xofs, font_yofs; @@ -1198,10 +1199,31 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b } } +#ifdef USE_NUMBUTS_LR_ALIGN + if (!drawstr_right && ELEM(but->type, NUM, NUMSLI) && (but->editstr == NULL)) { + drawstr_right = strchr(but->drawstr + but->ofs, ':'); + if (drawstr_right) { + drawstr_right++; + drawstr_left_len = (drawstr_right - but->drawstr); + + while (*drawstr_right == ' ') { + drawstr_right++; + } + } + else { + /* no prefix, even so use only cpoin */ + drawstr_right = but->drawstr + but->ofs; + use_right_only = true; + } + } +#endif + glColor4ubv((unsigned char *)wcol->text); - uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs, - drawstr_left_len - but->ofs, &font_xofs, &font_yofs); + if (!use_right_only) { + uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs, + drawstr_left_len - but->ofs, &font_xofs, &font_yofs); + } if (but->menu_key != '\0') { char fixedbuf[128]; @@ -2273,7 +2295,7 @@ static void widget_numbut_draw(uiWidgetColors *wcol, rcti *rect, int state, int { uiWidgetBase wtb; const float rad = 0.5f * BLI_rcti_size_y(rect); - float textofs = rad * 0.75f; + float textofs = rad * 0.85f; if (state & UI_SELECT) SWAP(short, wcol->shadetop, wcol->shadedown); -- cgit v1.2.3