[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50942] trunk/blender/source/blender/ editors/interface/interface_widgets.c: Fix #32673: long strings were wrongly clipped when modifying

Sergey Sharybin sergey.vfx at gmail.com
Fri Sep 28 13:28:23 CEST 2012


Revision: 50942
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50942
Author:   nazgul
Date:     2012-09-28 11:28:23 +0000 (Fri, 28 Sep 2012)
Log Message:
-----------
Fix #32673: long strings were wrongly clipped when modifying

It was a regression in svn revision 50676 -- button's string width
should be calculated taking button offset into account.

However, check for button offset should check string width without
offset taken into account.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50676

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	2012-09-28 11:02:43 UTC (rev 50941)
+++ trunk/blender/source/blender/editors/interface/interface_widgets.c	2012-09-28 11:28:23 UTC (rev 50942)
@@ -1014,42 +1014,42 @@
 	if (fstyle->kerning == 1) /* for BLF_width */
 		BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
 
-	if ((but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr)) <= okwidth) {
+	/* define ofs dynamically */
+	if (but->ofs > but->pos)
+		but->ofs = but->pos;
+
+	if (BLF_width(fstyle->uifont_id, but->drawstr) <= okwidth)
 		but->ofs = 0;
-	}
-	else {
-		/* define ofs dynamically */
-		if (but->ofs > but->pos)
-			but->ofs = but->pos;
 
-		while (but->strwidth > okwidth) {
-			float width;
-			char buf[UI_MAX_DRAW_STR];
+	but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
 
-			/* copy draw string */
-			BLI_strncpy_utf8(buf, but->drawstr, sizeof(buf));
-			/* string position of cursor */
-			buf[but->pos] = 0;
-			width = BLF_width(fstyle->uifont_id, buf + but->ofs);
+	while (but->strwidth > okwidth) {
+		float width;
+		char buf[UI_MAX_DRAW_STR];
 
-			/* if cursor is at 20 pixels of right side button we clip left */
-			if (width > okwidth - 20) {
-				ui_text_clip_give_next_off(but);
-			}
-			else {
-				int len, bytes;
-				/* shift string to the left */
-				if (width < 20 && but->ofs > 0)
-					ui_text_clip_give_prev_off(but);
-				len = strlen(but->drawstr);
-				bytes = BLI_str_utf8_size(BLI_str_find_prev_char_utf8(but->drawstr, but->drawstr + len));
-				but->drawstr[len - bytes] = 0;
-			}
+		/* copy draw string */
+		BLI_strncpy_utf8(buf, but->drawstr, sizeof(buf));
+		/* string position of cursor */
+		buf[but->pos] = 0;
+		width = BLF_width(fstyle->uifont_id, buf + but->ofs);
 
-			but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+		/* if cursor is at 20 pixels of right side button we clip left */
+		if (width > okwidth - 20) {
+			ui_text_clip_give_next_off(but);
+		}
+		else {
+			int len, bytes;
+			/* shift string to the left */
+			if (width < 20 && but->ofs > 0)
+				ui_text_clip_give_prev_off(but);
+			len = strlen(but->drawstr);
+			bytes = BLI_str_utf8_size(BLI_str_find_prev_char_utf8(but->drawstr, but->drawstr + len));
+			but->drawstr[len - bytes] = 0;
+		}
 
-			if (but->strwidth < 10) break;
-		}
+		but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+
+		if (but->strwidth < 10) break;
 	}
 
 	if (fstyle->kerning == 1) {




More information about the Bf-blender-cvs mailing list