mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibGUI: Elide the text in GCheckBox and GRadioButton when low on space.
This commit is contained in:
parent
be62b42352
commit
817ac9c22b
2 changed files with 12 additions and 10 deletions
|
@ -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)
|
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()) {
|
if (!is_enabled()) {
|
||||||
painter.draw_text(rect.translated(1, 1), text(), font, text_alignment, Color::White, TextElision::Right);
|
painter.draw_text(clipped_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, text(), font, text_alignment, Color::from_rgb(0x808080), TextElision::Right);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text().is_empty())
|
if (text().is_empty())
|
||||||
return;
|
return;
|
||||||
painter.draw_text(rect, text(), font, text_alignment, foreground_color(), TextElision::Right);
|
painter.draw_text(clipped_rect, text(), font, text_alignment, foreground_color(), TextElision::Right);
|
||||||
if (is_focused()) {
|
if (is_focused())
|
||||||
Rect focus_rect = { 0, 0, font.width(text()), font.glyph_height() };
|
painter.draw_rect(clipped_rect.inflated(6, 4), Color(140, 140, 140));
|
||||||
focus_rect.inflate(6, 4);
|
|
||||||
focus_rect.center_within(rect);
|
|
||||||
painter.draw_rect(focus_rect, Color(140, 140, 140));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,11 @@ void GButton::paint_event(GPaintEvent& event)
|
||||||
content_rect.set_width(content_rect.width() - m_icon->width() - 4);
|
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()
|
void GButton::click()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue