mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-11 15:29:28 -05:00
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:
parent
ff7a9d10cb
commit
e74a9f3b41
@ -365,9 +365,13 @@ void Text::set(std::string_view value) {
|
|||||||
void Text::paint(Painter& painter) {
|
void Text::paint(Painter& painter) {
|
||||||
const auto rect = screen_rect();
|
const auto rect = screen_rect();
|
||||||
auto s = has_focus() ? style().invert() : style();
|
auto s = has_focus() ? style().invert() : style();
|
||||||
|
auto max_len = (unsigned)rect.width() / s.font.char_width();
|
||||||
|
|
||||||
painter.fill_rectangle(rect, s.background);
|
painter.fill_rectangle(rect, s.background);
|
||||||
|
|
||||||
|
if (text.length() > max_len)
|
||||||
|
text.resize(max_len);
|
||||||
|
|
||||||
painter.draw_string(
|
painter.draw_string(
|
||||||
rect.location(),
|
rect.location(),
|
||||||
s,
|
s,
|
||||||
|
Loading…
Reference in New Issue
Block a user