Skip to content

Commit e5c4c58

Browse files
fix(graphics): measure ellipsis before shrinking in force_fit_string (#7165)
* fix(graphics): measure ellipsis before shrinking in force_fit_string * chore(comments): clarify why ellipsis measurement is needed before shrinking
1 parent e567ae7 commit e5c4c58

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

code/graphics/software/font.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,15 @@ namespace font
590590
str[len] = ellipsis_char;
591591
}
592592

593+
// measure with ellipsis before shrinking further (the ellipsis characters could be narrower than the characters they replaced)
594+
gr_get_string_size(&w, nullptr, str, scale, len + ellipsis_len);
595+
593596
// move the ellipsis back until the whole string fits
594597
while (len > 0 && w > max_width) {
595598
--len;
596599
str[len] = ellipsis_char;
597600
gr_get_string_size(&w, nullptr, str, scale, len + ellipsis_len);
598-
};
601+
}
599602

600603
str[len + ellipsis_len] = 0;
601604
}

0 commit comments

Comments
 (0)