Limit text string length to fit Text widget rectangle (#1370)

* Limit string length to fit Text rectangle

* Update ui_widget.cpp
This commit is contained in:
Mark Thompson 2023-08-13 13:34:46 -05:00 committed by GitHub
parent ff7a9d10cb
commit e74a9f3b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -365,9 +365,13 @@ void Text::set(std::string_view value) {
void Text::paint(Painter& painter) {
const auto rect = screen_rect();
auto s = has_focus() ? style().invert() : style();
auto max_len = (unsigned)rect.width() / s.font.char_width();
painter.fill_rectangle(rect, s.background);
if (text.length() > max_len)
text.resize(max_len);
painter.draw_string(
rect.location(),
s,