LibGUI: Elide the text in GCheckBox and GRadioButton when low on space.

This commit is contained in:
Andreas Kling 2019-05-25 04:01:22 +02:00
parent be62b42352
commit 817ac9c22b
Notes: sideshowbarker 2024-07-19 13:57:43 +09:00
2 changed files with 12 additions and 10 deletions

View file

@ -110,19 +110,17 @@ void GAbstractButton::keydown_event(GKeyEvent& event)
void GAbstractButton::paint_text(GPainter& painter, const Rect& rect, const Font& font, TextAlignment text_alignment)
{
auto clipped_rect = rect.intersected(this->rect());
if (!is_enabled()) {
painter.draw_text(rect.translated(1, 1), text(), font, text_alignment, Color::White, TextElision::Right);
painter.draw_text(rect, text(), font, text_alignment, Color::from_rgb(0x808080), TextElision::Right);
painter.draw_text(clipped_rect.translated(1, 1), text(), font, text_alignment, Color::White, TextElision::Right);
painter.draw_text(clipped_rect, text(), font, text_alignment, Color::from_rgb(0x808080), TextElision::Right);
return;
}
if (text().is_empty())
return;
painter.draw_text(rect, text(), font, text_alignment, foreground_color(), TextElision::Right);
if (is_focused()) {
Rect focus_rect = { 0, 0, font.width(text()), font.glyph_height() };
focus_rect.inflate(6, 4);
focus_rect.center_within(rect);
painter.draw_rect(focus_rect, Color(140, 140, 140));
}
painter.draw_text(clipped_rect, text(), font, text_alignment, foreground_color(), TextElision::Right);
if (is_focused())
painter.draw_rect(clipped_rect.inflated(6, 4), Color(140, 140, 140));
}

View file

@ -49,7 +49,11 @@ void GButton::paint_event(GPaintEvent& event)
content_rect.set_width(content_rect.width() - m_icon->width() - 4);
}
paint_text(painter, content_rect, font, text_alignment());
Rect text_rect { 0, 0, font.width(text()), font.glyph_height() };
if (text_rect.width() > content_rect.width())
text_rect.set_width(content_rect.width());
text_rect.center_within(content_rect);
paint_text(painter, text_rect, font, text_alignment());
}
void GButton::click()