From e74a9f3b413c93b4a4078eb69284849cf66a51f8 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Sun, 13 Aug 2023 13:34:46 -0500 Subject: [PATCH] Limit text string length to fit Text widget rectangle (#1370) * Limit string length to fit Text rectangle * Update ui_widget.cpp --- firmware/common/ui_widget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index 9b6e5883..1e4dc9c0 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -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,