[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24484] trunk/blender/source/blender/ editors/interface/interface_widgets.c: * Fix for [#19488] Small slider = hidden values

Matt Ebb matt at mke3.net
Wed Nov 11 11:27:25 CET 2009


Revision: 24484
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24484
Author:   broken
Date:     2009-11-11 11:27:25 +0100 (Wed, 11 Nov 2009)

Log Message:
-----------
* Fix for [#19488] Small slider = hidden values

Now number fields use a new method of clipping text when the available space is small:
http://vimeo.com/7545600

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface_widgets.c

Modified: trunk/blender/source/blender/editors/interface/interface_widgets.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_widgets.c	2009-11-11 10:07:52 UTC (rev 24483)
+++ trunk/blender/source/blender/editors/interface/interface_widgets.c	2009-11-11 10:27:25 UTC (rev 24484)
@@ -806,6 +806,46 @@
 	}
 }
 
+static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
+{
+	int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
+	int okwidth= rect->xmax-rect->xmin - border;
+	char *cpoin=NULL;
+	char *end = but->drawstr + strlen(but->drawstr);
+	
+	/* need to set this first */
+	uiStyleFontSet(fstyle);
+	
+	but->strwidth= BLF_width(but->drawstr);
+	but->ofs= 0;
+	
+	/* find the space after ':' separator */
+	cpoin= strchr(but->drawstr, ':');
+	cpoin += 2;
+	if (cpoin >= end) cpoin = NULL;
+	
+	/* chop off the text label, with ofs */
+	if (cpoin) {
+		while ((but->drawstr + but->ofs < cpoin) && (but->strwidth > okwidth))
+		{
+			but->ofs++;
+			but->strwidth= BLF_width(but->drawstr+but->ofs);
+		}
+	}
+	
+	/* once the label's gone, chop off the least significant digits */
+	while(but->strwidth > okwidth ) {
+		int pos= strlen(but->drawstr);
+		
+		but->drawstr[ pos-1 ] = 0;
+		pos--;
+		
+		but->strwidth= BLF_width(but->drawstr+but->ofs);
+		if(but->strwidth < 10) break;
+	}
+}
+
+
 static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
 {
 //	int transopts;
@@ -893,9 +933,12 @@
 {
 	
 	if(but==NULL) return;
-	
-	/* cutting off from left part */
-	if ELEM5(but->type, NUM, NUMABS, NUMSLI, SLI, TEX) {	
+
+	/* clip but->drawstr to fit in available space */
+	if (ELEM4(but->type, NUM, NUMABS, NUMSLI, SLI)) {
+		ui_text_label_rightclip(fstyle, but, rect);
+	}
+	else if (but->type == TEX) {	
 		ui_text_leftclip(fstyle, but, rect);
 	}
 	else but->ofs= 0;
@@ -1666,7 +1709,7 @@
 {
 	uiWidgetBase wtb;
 	float rad= 0.5f*(rect->ymax - rect->ymin);
-	
+
 	widget_init(&wtb);
 	
 	/* fully rounded */
@@ -1888,7 +1931,6 @@
 	rcti rect1;
 	double value;
 	float offs, fac;
-	int textoffs;
 	char outline[3];
 	
 	widget_init(&wtb);
@@ -1898,7 +1940,6 @@
 	
 	/* fully rounded */
 	offs= 0.5f*(rect->ymax - rect->ymin);
-	textoffs= offs;
 	round_box_edges(&wtb, roundboxalign, rect, offs);
 
 	wtb.outline= 0;
@@ -1940,8 +1981,8 @@
 	widgetbase_draw(&wtb, wcol);
 	
 	/* text space */
-	rect->xmin += textoffs;
-	rect->xmax -= textoffs;
+	rect->xmin += offs*0.75f;
+	rect->xmax -= offs*0.75f;
 }
 
 static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)





More information about the Bf-blender-cvs mailing list