Fix #100784: Truncate Text with Ellipsis inside Number Inputs #115958
|
@ -1700,6 +1700,19 @@ static void ui_text_clip_right_label(const uiFontStyle *fstyle, uiBut *but, cons
|
|||
UI_fontstyle_set(fstyle);
|
||||
|
||||
but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr));
|
||||
|
||||
/* The string already fits, so do nothing. */
|
||||
if (but->strwidth <= okwidth) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char sep[] = BLI_STR_UTF8_HORIZONTAL_ELLIPSIS;
|
||||
const int sep_len = sizeof(sep) - 1;
|
||||
const float sep_strwidth = BLF_width(fstyle->uifont_id, sep, sep_len + 1);
|
||||
|
||||
/* Assume the string will have an ellipsis for initial tests. */
|
||||
but->strwidth += sep_strwidth;
|
||||
|
||||
but->ofs = 0;
|
||||
|
||||
/* First shorten number-buttons eg,
|
||||
|
@ -1727,9 +1740,11 @@ static void ui_text_clip_right_label(const uiFontStyle *fstyle, uiBut *but, cons
|
|||
drawstr_len -= bytes;
|
||||
// BLI_assert(strlen(but->drawstr) == drawstr_len);
|
||||
|
||||
but->strwidth = BLF_width(
|
||||
fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs);
|
||||
if (but->strwidth < 10) {
|
||||
but->strwidth = BLF_width(fstyle->uifont_id,
|
||||
but->drawstr + but->ofs,
|
||||
sizeof(but->drawstr) - but->ofs) +
|
||||
sep_strwidth;
|
||||
if (but->strwidth < sep_strwidth) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1758,6 +1773,15 @@ static void ui_text_clip_right_label(const uiFontStyle *fstyle, uiBut *but, cons
|
|||
but->strwidth = strwidth;
|
||||
but->drawstr[drawstr_len] = 0;
|
||||
}
|
||||
|
||||
cpoin = strrchr(but->drawstr, ':');
|
||||
if (cpoin && (cpoin - but->drawstr > 0) && (drawstr_len < (sizeof(but->drawstr) - sep_len))) {
|
||||
/* We shortened the string and still have a colon, so insert ellipsis. */
|
||||
memmove(cpoin + sep_len, cpoin, cpend - cpoin);
|
||||
memcpy(cpoin, sep, sep_len);
|
||||
but->strwidth = BLF_width(
|
||||
fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_INPUT_IME
|
||||
|
|
Loading…
Reference in New Issue