mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
LibGUI: Make the LinkLabel widget keyboard-friendly
Make it tab-focusable and activate it with the return key. :^)
This commit is contained in:
parent
6b6594e3d0
commit
bdff88d8d5
4 changed files with 29 additions and 8 deletions
|
@ -37,6 +37,7 @@ LinkLabel::LinkLabel(String text)
|
|||
: Label(move(text))
|
||||
{
|
||||
set_foreground_role(Gfx::ColorRole::Link);
|
||||
set_focus_policy(FocusPolicy::TabFocus);
|
||||
}
|
||||
|
||||
void LinkLabel::mousedown_event(MouseEvent& event)
|
||||
|
@ -47,14 +48,25 @@ void LinkLabel::mousedown_event(MouseEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void LinkLabel::keydown_event(KeyEvent& event)
|
||||
{
|
||||
Label::keydown_event(event);
|
||||
if (event.key() == KeyCode::Key_Return || event.key() == KeyCode::Key_Space) {
|
||||
if (on_click)
|
||||
on_click();
|
||||
}
|
||||
}
|
||||
|
||||
void LinkLabel::paint_event(PaintEvent& event)
|
||||
{
|
||||
Label::paint_event(event);
|
||||
GUI::Painter painter(*this);
|
||||
|
||||
if (m_hovered)
|
||||
painter.draw_line({ 0, rect().bottom() }, { font().width(text()), rect().bottom() },
|
||||
Widget::palette().link());
|
||||
painter.draw_line({ 0, rect().bottom() }, { font().width(text()), rect().bottom() }, palette().link());
|
||||
|
||||
if (is_focused())
|
||||
painter.draw_focus_rect(text_rect(), palette().focus_outline());
|
||||
}
|
||||
|
||||
void LinkLabel::enter_event(Core::Event& event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue