[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34419] trunk/blender/source/blender/ editors/interface: Bugfix #25656

Ton Roosendaal ton at blender.org
Thu Jan 20 19:34:49 CET 2011


Revision: 34419
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34419
Author:   ton
Date:     2011-01-20 18:34:48 +0000 (Thu, 20 Jan 2011)
Log Message:
-----------
Bugfix #25656

Fixed one of oldest annoyances in Blender: the text input button!
It always behaved stupid when you had clipped text in a button.

Now while using arrows the cursor will move as expected, and only
internally shift contents when cursor reaches edge of button.

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

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2011-01-20 16:29:43 UTC (rev 34418)
+++ trunk/blender/source/blender/editors/interface/interface.c	2011-01-20 18:34:48 UTC (rev 34419)
@@ -523,6 +523,7 @@
 #endif
 				but->active= oldbut->active;
 				but->pos= oldbut->pos;
+				but->ofs= oldbut->ofs;
 				but->editstr= oldbut->editstr;
 				but->editval= oldbut->editval;
 				but->editvec= oldbut->editvec;

Modified: trunk/blender/source/blender/editors/interface/interface_widgets.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_widgets.c	2011-01-20 16:29:43 UTC (rev 34418)
+++ trunk/blender/source/blender/editors/interface/interface_widgets.c	2011-01-20 18:34:48 UTC (rev 34419)
@@ -871,28 +871,42 @@
 	if (fstyle->kerning==1)	/* for BLF_width */
 		BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
 
-	but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr);
-	but->ofs= 0;
+	/* if text editing we define ofs dynamically */
+	if(but->editstr && but->pos >= 0) {
+		if(but->ofs > but->pos)
+			but->ofs= but->pos;
+	}
+	else but->ofs= 0;
 	
-	while(but->strwidth > okwidth ) {
+	but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+	
+	while(but->strwidth > okwidth) {
 		
-		but->ofs++;
-		but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
-		
-		/* textbut exception */
-		if(but->editstr && but->pos != -1) {
-			int pos= but->pos+1;
+		/* textbut exception, clip right when... */
+		if(but->editstr && but->pos >= 0) {
+			float width;
+			char buf[256];
 			
-			if(pos-1 < but->ofs) {
-				pos= but->ofs-pos+1;
-				but->ofs -= pos;
-				if(but->ofs<0) {
-					but->ofs= 0;
-					pos--;
-				}
-				but->drawstr[ strlen(but->drawstr)-pos ]= 0;
+			/* copy draw string */
+			BLI_strncpy(buf, but->drawstr, sizeof(buf));
+			/* string position of cursor */
+			buf[but->pos]= 0;
+			width= BLF_width(fstyle->uifont_id, buf+but->ofs);
+			
+			/* if cursor is at 20 pixels of right side button we clip left */
+			if(width > okwidth-20)
+				but->ofs++;
+			else {
+				/* shift string to the left */
+				if(width < 20 && but->ofs > 0)
+					but->ofs--;
+				but->drawstr[ strlen(but->drawstr)-1 ]= 0;
 			}
 		}
+		else
+			but->ofs++;
+
+		but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
 		
 		if(but->strwidth < 10) break;
 	}




More information about the Bf-blender-cvs mailing list