[Bf-blender-cvs] [dde5e5c] master: User Interface: Align number buttons labels to the left, number right

Campbell Barton noreply at git.blender.org
Wed Dec 11 11:28:19 CET 2013


Commit: dde5e5ce2581ffd544b442c58d6eefbc1ff61772
Author: Campbell Barton
Date:   Wed Dec 11 21:27:13 2013 +1100
http://developer.blender.org/rBdde5e5ce2581ffd544b442c58d6eefbc1ff61772

User Interface: Align number buttons labels to the left, number right

===================================================================

M	source/blender/blenkernel/intern/unit.c
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_widgets.c

===================================================================

diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index 8e92f86..17aad7a 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 79db94e..aaaf64b 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 3ef7117..cbc1cd2 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 d353983..9826f07 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);




More information about the Bf-blender-cvs mailing list