From c22f9cc09737ee49477a896c2562094b6d4028ba Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 11 Oct 2023 20:11:43 +0000 Subject: [PATCH] Add action key support for enter to the Readme --- Readme.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Readme.md b/Readme.md index 56f053d..026c492 100644 --- a/Readme.md +++ b/Readme.md @@ -367,6 +367,33 @@ can use `NavMarker` in the [`mark`][module-marking] module. A usage demo is available in [the `marking.rs` example][example-marking]. +### Menu action with keyboard return (enter) key + +The default [`InputMapping`] key to trigger menu actions is the space key. +To use the return key, change the `key_action` attribute. + +Otherwise, if you are not using default input handling, add this system: + +```rust +use bevy::prelude::*; +use bevy_ui_navigation::prelude::{NavRequest, NavRequestSystem}; + +fn main() { + App::new() + // ... + .add_systems(Update, ( + return_trigger_action.before(NavRequestSystem), + )); +} + +fn return_trigger_action(mut requests: EventWriter, input: Res>) { + if input.just_pressed(KeyCode::Return) { + requests.send(NavRequest::Action); + } +} +``` + + ## Changelog * `0.8.2`: Fix offsetting of mouse focus with `UiCamera`s with a transform set