[Bf-blender-cvs] [de3f369b30e] master: UI: Use Ellipsis for Short Truncated Text

Harley Acheson noreply at git.blender.org
Tue Jan 26 19:18:42 CET 2021


Commit: de3f369b30e5d08415b8cff14e462ec6d18689ea
Author: Harley Acheson
Date:   Tue Jan 26 10:17:37 2021 -0800
Branches: master
https://developer.blender.org/rBde3f369b30e5d08415b8cff14e462ec6d18689ea

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

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

M	source/blender/editors/interface/interface_widgets.c

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

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;
     }
   }
 }



More information about the Bf-blender-cvs mailing list