Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2018-10-03 17:22:10 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-10-03 17:24:35 +0300
commit9c09998530041744a183dfae3da435806272623b (patch)
tree9a6b45fd48adc2ac8ad47c1035ec228354e3c6c5
parentfb60fb055d680a037a7808aeb3304c34ff0c06f7 (diff)
UI strings: Fix asserts in 'middle-splitting' fitting string code.
The problem is that string width computing is performed in integers (pixels), which can generate a rather annoying error (a few pixels)... Simply work around that for now, by trimming an extra middle char when needed.
-rw-r--r--source/blender/editors/interface/interface_widgets.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 217893a4ecc..e738a3f6a6d 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1521,6 +1521,16 @@ float UI_text_clip_middle_ex(
memmove(str + l_end + sep_len, str + r_offset, r_len);
memcpy(str + l_end, sep, sep_len);
final_lpart_len = (size_t)(l_end + sep_len + r_len - 1); /* -1 to remove trailing '\0'! */
+
+ while (BLF_width(fstyle->uifont_id, str, max_len) > okwidth) {
+ /* This will happen because a lot of string width processing is done in integer pixels,
+ * which can introduce a rather high error in the end (about 2 pixels or so).
+ * Only one char removal shall ever be needed in real-life situation... */
+ r_len--;
+ final_lpart_len--;
+ char *c = str + l_end + sep_len;
+ memmove(c, c + 1, r_len);
+ }
}
}