core: Allow pressing buttons with keyboard

This patch allows the keyboard to be used (Enter/Space) to press buttons.
This commit is contained in:
Kamil Jarosz 2024-05-07 00:41:21 +02:00 committed by Nathan Adams
parent 18d9035685
commit da9c9527e5
1 changed files with 19 additions and 0 deletions

View File

@ -1125,6 +1125,25 @@ impl Player {
} }
} }
// KeyPress events also take precedence over keyboard navigation.
// Note that keyboard navigation works only when the highlight is visible.
if !key_press_handled && context.focus_tracker.highlight().is_visible() {
if let Some(focus) = context.focus_tracker.get() {
if matches!(
event,
PlayerEvent::KeyDown {
key_code: KeyCode::Return,
..
} | PlayerEvent::TextInput { codepoint: ' ' }
) {
// The button/clip is pressed and then immediately released.
// We do not have to wait for KeyUp.
focus.handle_clip_event(context, ClipEvent::Press);
focus.handle_clip_event(context, ClipEvent::Release);
}
}
}
Self::run_actions(context); Self::run_actions(context);
}); });