mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
KeyboardMapper: Fix discrepancy between cursor and button clickability
KeyButton now only responds to clicks on the key-cap's face. This corresponds to when the cursor switches from the default arrow to a hand.
This commit is contained in:
parent
35afd32a51
commit
64684cbd5d
2 changed files with 14 additions and 7 deletions
|
@ -53,7 +53,7 @@ void KeyButton::paint_event(GUI::PaintEvent& event)
|
||||||
|
|
||||||
void KeyButton::click(unsigned)
|
void KeyButton::click(unsigned)
|
||||||
{
|
{
|
||||||
if (on_click)
|
if (on_click && m_face_hovered)
|
||||||
on_click();
|
on_click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,17 +64,22 @@ void KeyButton::mousemove_event(GUI::MouseEvent& event)
|
||||||
|
|
||||||
Gfx::IntRect key_cap_face_rect = { rect().x() + 7, rect().y() + 4, rect().width() - 14, rect().height() - 14 };
|
Gfx::IntRect key_cap_face_rect = { rect().x() + 7, rect().y() + 4, rect().width() - 14, rect().height() - 14 };
|
||||||
|
|
||||||
if (key_cap_face_rect.contains(event.position())) {
|
set_face_hovered(key_cap_face_rect.contains(event.position()));
|
||||||
window()->set_cursor(Gfx::StandardCursor::Hand);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window()->set_cursor(Gfx::StandardCursor::Arrow);
|
|
||||||
|
|
||||||
AbstractButton::mousemove_event(event);
|
AbstractButton::mousemove_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyButton::leave_event(Core::Event& event)
|
void KeyButton::leave_event(Core::Event& event)
|
||||||
{
|
{
|
||||||
window()->set_cursor(Gfx::StandardCursor::Arrow);
|
set_face_hovered(false);
|
||||||
AbstractButton::leave_event(event);
|
AbstractButton::leave_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyButton::set_face_hovered(bool value)
|
||||||
|
{
|
||||||
|
m_face_hovered = value;
|
||||||
|
if (m_face_hovered)
|
||||||
|
set_override_cursor(Gfx::StandardCursor::Hand);
|
||||||
|
else
|
||||||
|
set_override_cursor(Gfx::StandardCursor::None);
|
||||||
|
}
|
||||||
|
|
|
@ -28,4 +28,6 @@ private:
|
||||||
KeyButton() = default;
|
KeyButton() = default;
|
||||||
|
|
||||||
bool m_pressed { false };
|
bool m_pressed { false };
|
||||||
|
bool m_face_hovered { false };
|
||||||
|
void set_face_hovered(bool value);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue