[Bf-blender-cvs] [2c7cb8c] master: Fix UI string clip (reverse search separator char)

Campbell Barton noreply at git.blender.org
Wed Jun 3 07:09:20 CEST 2015


Commit: 2c7cb8ce59da8b4d9fb9d9128c736e6f6560aa01
Author: Campbell Barton
Date:   Wed Jun 3 15:01:02 2015 +1000
Branches: master
https://developer.blender.org/rB2c7cb8ce59da8b4d9fb9d9128c736e6f6560aa01

Fix UI string clip (reverse search separator char)

The string may have many '|' characters, only the last is clipped.

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/space_file/file_draw.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index e5ab7f2..0b400e2 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -322,7 +322,7 @@ void UI_draw_widget_scroll(struct uiWidgetColors *wcol, const struct rcti *rect,
 /* Shortening string helper. */
 float UI_text_clip_middle_ex(
         struct uiFontStyle *fstyle, char *str, float okwidth, const float minwidth,
-        const size_t max_len, const char *rpart_sep);
+        const size_t max_len, const char rpart_sep);
 
 /* Callbacks
  *
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 9efbf53..8190df6 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -970,7 +970,7 @@ static void ui_text_clip_right_ex(
  */
 float UI_text_clip_middle_ex(
         uiFontStyle *fstyle, char *str, float okwidth, const float minwidth,
-        const size_t max_len, const char *rpart_sep)
+        const size_t max_len, const char rpart_sep)
 {
 	float strwidth;
 
@@ -1003,7 +1003,7 @@ float UI_text_clip_middle_ex(
 		size_t final_lpart_len;
 
 		if (rpart_sep) {
-			rpart = strstr(str, rpart_sep);
+			rpart = strrchr(str, rpart_sep);
 
 			if (rpart) {
 				rpart_len = strlen(rpart);
@@ -1085,14 +1085,14 @@ static void ui_text_clip_middle(uiFontStyle *fstyle, uiBut *but, const rcti *rec
 	const float minwidth = (float)(UI_DPI_ICON_SIZE) / but->block->aspect * 2.0f;
 
 	but->ofs = 0;
-	but->strwidth = UI_text_clip_middle_ex(fstyle, but->drawstr, okwidth, minwidth, max_len, NULL);
+	but->strwidth = UI_text_clip_middle_ex(fstyle, but->drawstr, okwidth, minwidth, max_len, '\0');
 }
 
 /**
  * Like ui_text_clip_middle(), but protect/preserve at all cost the right part of the string after sep.
  * Useful for strings with shortcuts (like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O').
  */
-static void ui_text_clip_middle_protect_right(uiFontStyle *fstyle, uiBut *but, const rcti *rect, const char *rsep)
+static void ui_text_clip_middle_protect_right(uiFontStyle *fstyle, uiBut *but, const rcti *rect, const char rsep)
 {
 	/* No margin for labels! */
 	const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f);
@@ -1610,7 +1610,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
 	}
 	else if (but->flag & UI_BUT_HAS_SEP_CHAR) {
 		/* Clip middle, but protect in all case right part containing the shortcut, if any. */
-		ui_text_clip_middle_protect_right(fstyle, but, rect, UI_SEP_CHAR_S);
+		ui_text_clip_middle_protect_right(fstyle, but, rect, UI_SEP_CHAR);
 	}
 	else {
 		ui_text_clip_middle(fstyle, but, rect);
@@ -4077,7 +4077,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic
 		const float minwidth = (float)(UI_DPI_ICON_SIZE);
 
 		BLI_strncpy(drawstr, name, sizeof(drawstr));
-		UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, NULL);
+		UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0');
 
 		glColor4ubv((unsigned char *)wt->wcol.text);
 		UI_fontstyle_draw(fstyle, rect, drawstr);
@@ -4144,7 +4144,7 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int
 		const float minwidth = (float)(UI_DPI_ICON_SIZE);
 
 		BLI_strncpy(drawstr, name, sizeof(drawstr));
-		UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, NULL);
+		UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0');
 
 		glColor4ubv((unsigned char *)wt->wcol.text);
 		UI_fontstyle_draw(fstyle, &trect, drawstr);
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 0a9a12e..0e4d885 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -310,7 +310,7 @@ static void file_draw_string(int sx, int sy, const char *string, float width, in
 	fs.align = align;
 
 	BLI_strncpy(fname, string, FILE_MAXFILE);
-	UI_text_clip_middle_ex(&fs, fname, width, UI_DPI_ICON_SIZE, sizeof(fname), NULL);
+	UI_text_clip_middle_ex(&fs, fname, width, UI_DPI_ICON_SIZE, sizeof(fname), '\0');
 
 	/* no text clipping needed, UI_fontstyle_draw does it but is a bit too strict (for buttons it works) */
 	rect.xmin = sx;




More information about the Bf-blender-cvs mailing list