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:
authorHarley Acheson <harley.acheson@gmail.com>2021-01-26 21:17:37 +0300
committerHarley Acheson <harley.acheson@gmail.com>2021-01-26 21:17:37 +0300
commitde3f369b30e5d08415b8cff14e462ec6d18689ea (patch)
tree44f6453e1bd27cc0ecd6c898651632a22864385d /source/blender/editors/interface/interface_widgets.c
parentcdb8209b35a198b078ff7cde4822ae0ff8440890 (diff)
UI: Use Ellipsis for Short Truncated Text
Allow use of ellipsis to indicate truncated text down to a single character. Differential Revision: https://developer.blender.org/D9483 Reviewed by Hans Goudey
Diffstat (limited to 'source/blender/editors/interface/interface_widgets.c')
-rw-r--r--source/blender/editors/interface/interface_widgets.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 3c720a39003..89720cbf17e 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1533,25 +1533,22 @@ static void ui_text_clip_right_ex(const uiFontStyle *fstyle,
{
BLI_assert(str[0]);
- /* If the trailing ellipsis takes more than 20% of all available width, just cut the string
- * (as using the ellipsis would remove even more useful chars, and we cannot show much
- * already!).
- */
- if (sep_strwidth / okwidth > 0.2f) {
- float tmp;
- const int l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth, &tmp);
- str[l_end] = '\0';
+ /* How many BYTES (not characters) of this utf-8 string can fit, along with appended ellipsis. */
+ int l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth - sep_strwidth, NULL);
+
+ if (l_end > 0) {
+ /* At least one character, so clip and add the ellipsis. */
+ memcpy(str + l_end, sep, sep_len + 1); /* +1 for trailing '\0'. */
if (r_final_len) {
- *r_final_len = (size_t)l_end;
+ *r_final_len = (size_t)(l_end) + sep_len;
}
}
else {
- float tmp;
- const int l_end = BLF_width_to_strlen(
- fstyle->uifont_id, str, max_len, okwidth - sep_strwidth, &tmp);
- memcpy(str + l_end, sep, sep_len + 1); /* +1 for trailing '\0'. */
+ /* Otherwise fit as much as we can without adding an ellipsis. */
+ l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth, NULL);
+ str[l_end] = '\0';
if (r_final_len) {
- *r_final_len = (size_t)(l_end) + sep_len;
+ *r_final_len = (size_t)l_end;
}
}
}