[Bf-blender-cvs] [c5a8a4e] master: Fix mismatch in strings length compute in filebrowser, leading to annoying '...' in longest filename.

Bastien Montagne noreply at git.blender.org
Wed May 27 17:26:16 CEST 2015


Commit: c5a8a4e9d8bda11cd8314473b190189fd1303c98
Author: Bastien Montagne
Date:   Wed May 27 17:15:48 2015 +0200
Branches: master
https://developer.blender.org/rBc5a8a4e9d8bda11cd8314473b190189fd1303c98

Fix mismatch in strings length compute in filebrowser, leading to annoying '...' in longest filename.

We must take kerning into account everywhere! Note this will disappear in upcomming filebrowser
refactor anyway.

Reported through IRC by Pablo (venomgfx), thanks.

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

M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/filesel.c

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

diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index deb2380..fb7b319 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -973,6 +973,10 @@ float UI_text_clip_middle_ex(
 {
 	float strwidth;
 
+	/* Add some epsilon to OK width, avoids 'ellipsing' text that nearly fits!
+     * Better to have a small piece of the last char cut out, than two remaining chars replaced by an allipsis... */
+	okwidth += 1.0f + UI_DPI_FAC;
+
 	BLI_assert(str[0]);
 
 	/* need to set this first */
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 2bd92b1..0a9a12e 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 + 1.0f, UI_DPI_ICON_SIZE, sizeof(fname), NULL);
+	UI_text_clip_middle_ex(&fs, fname, width, UI_DPI_ICON_SIZE, sizeof(fname), NULL);
 
 	/* no text clipping needed, UI_fontstyle_draw does it but is a bit too strict (for buttons it works) */
 	rect.xmin = sx;
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 29a8a06..62b4bfa 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -401,8 +401,20 @@ void ED_fileselect_layout_tilepos(FileLayout *layout, int tile, int *x, int *y)
 float file_string_width(const char *str)
 {
 	uiStyle *style = UI_style_get();
+	float width;
+
 	UI_fontstyle_set(&style->widget);
-	return BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
+	if (style->widget.kerning == 1) {  /* for BLF_width */
+		BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
+	}
+
+	width = BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
+
+	if (style->widget.kerning == 1) {
+		BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
+	}
+
+	return width;
 }
 
 float file_font_pointsize(void)




More information about the Bf-blender-cvs mailing list