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
This commit is contained in:
Harley Acheson 2021-01-26 10:17:37 -08:00
parent cdb8209b35
commit de3f369b30
1 changed files with 13 additions and 16 deletions

View File

@ -1533,27 +1533,24 @@ 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';
if (r_final_len) {
*r_final_len = (size_t)l_end;
}
}
else {
float tmp;
const int l_end = BLF_width_to_strlen(
fstyle->uifont_id, str, max_len, okwidth - sep_strwidth, &tmp);
/* 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) + sep_len;
}
}
else {
/* 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;
}
}
}
/**