1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:27:46 +00:00

LibGUI+LibGfx: Improve focus rect appearance

Draw a dotted focus rect to make it stand out more. Also make it much
larger on regular text-only GUI::Buttons.
This commit is contained in:
Andreas Kling 2020-10-26 20:43:59 +01:00
parent f6084d42d9
commit b7dfa83223
6 changed files with 47 additions and 2 deletions

View file

@ -176,8 +176,6 @@ void AbstractButton::paint_text(Painter& painter, const Gfx::IntRect& rect, cons
if (text().is_empty())
return;
painter.draw_text(clipped_rect, text(), font, text_alignment, palette().color(foreground_role()), Gfx::TextElision::Right);
if (is_focused())
painter.draw_rect(clipped_rect.inflated(6, 4), palette().focus_outline());
}
void AbstractButton::change_event(Event& event)

View file

@ -92,6 +92,15 @@ void Button::paint_event(PaintEvent& event)
text_rect.set_width(content_rect.width());
text_rect.align_within(content_rect, text_alignment());
paint_text(painter, text_rect, font, text_alignment());
if (is_focused()) {
Gfx::IntRect focus_rect;
if (m_icon)
focus_rect = text_rect.inflated(6, 6);
else
focus_rect = rect().shrunken(8, 8);
painter.draw_focus_rect(focus_rect, palette().focus_outline());
}
}
void Button::click(unsigned modifiers)

View file

@ -70,6 +70,9 @@ void CheckBox::paint_event(PaintEvent& event)
Gfx::StylePainter::paint_check_box(painter, box_rect, palette(), is_enabled(), is_checked(), is_being_pressed());
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);
if (is_focused())
painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline());
}
void CheckBox::click(unsigned)

View file

@ -66,6 +66,9 @@ void RadioButton::paint_event(PaintEvent& event)
Gfx::IntRect text_rect { circle_rect.right() + 4, 0, font().width(text()), font().glyph_height() };
text_rect.center_vertically_within(rect());
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);
if (is_focused())
painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline());
}
template<typename Callback>