1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 06:37:36 +00:00

GButton: Only draw focus rect if there is a caption text.

This commit is contained in:
Andreas Kling 2019-05-16 14:05:28 +02:00
parent 6f73a549fa
commit ee363faf10

View file

@ -62,12 +62,14 @@ 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);
} }
if (is_enabled()) { if (is_enabled()) {
painter.draw_text(content_rect, m_caption, font, text_alignment(), foreground_color(), TextElision::Right); if (!m_caption.is_empty()) {
if (is_focused()) { painter.draw_text(content_rect, m_caption, font, text_alignment(), foreground_color(), TextElision::Right);
Rect focus_rect = { 0, 0, font.width(m_caption), font.glyph_height() }; if (is_focused()) {
focus_rect.inflate(6, 4); Rect focus_rect = { 0, 0, font.width(m_caption), font.glyph_height() };
focus_rect.center_within(content_rect); focus_rect.inflate(6, 4);
painter.draw_rect(focus_rect, Color(140, 140, 140)); focus_rect.center_within(content_rect);
painter.draw_rect(focus_rect, Color(140, 140, 140));
}
} }
} else { } else {
painter.draw_text(content_rect.translated(1, 1), m_caption, font, text_alignment(), Color::White, TextElision::Right); painter.draw_text(content_rect.translated(1, 1), m_caption, font, text_alignment(), Color::White, TextElision::Right);