Add a simple directional UI navigation example#17224
Add a simple directional UI navigation example#17224alice-i-cecile merged 20 commits intobevyengine:mainfrom
Conversation
thread 'main' panicked at C:\Users\alice\.cargo\registry\src\index.crates.io-Panic was: 6f17d22bba15001f\accesskit_consumer-0.26.0\src\tree.rs:34:13: Focused id #4294967304 is not in the node list
|
The generated |
cargo run -p build-templated-pages -- update examples
|
Sent a couple tiny PRs your way |
Fix centering of buttons and their contents
…tton Fix enter button and change background color instead of printing
| } | ||
| } | ||
|
|
||
| // We're spawning a simple 3x3 grid of buttons |
There was a problem hiding this comment.
| // We're spawning a simple 3x3 grid of buttons | |
| // We're spawning a simple 3x5 grid of buttons |
| // Allow the grid to take up the full height and width of the window | ||
| width: Val::Percent(60.), |
There was a problem hiding this comment.
IMO
- Make instructions node wider, maybe
Px(300.0) - Leave this at
100.0. - Adjust this comment to say "take up the full height and the rest of the width."
Seems okay for the grid to not be centered in the screen to me.
| // to capture the actual intent of the user | ||
| fn universal_button_click_behavior( | ||
| // We're using a on-mouse-down trigger to improve responsiveness; | ||
| // Clicked is better when you want roll-off cancellation |
There was a problem hiding this comment.
Might be nicer to have separate effects that get triggered on Pressed and Clicked rather than explain why it looks like we're doing the "wrong" thing.
But that could be a future improvement.
| width: Val::Px(200.0), | ||
| justify_content: JustifyContent::Center, | ||
| align_items: AlignItems::Center, | ||
| margin: UiRect::all(Val::Px(16.0)), |
There was a problem hiding this comment.
| margin: UiRect::all(Val::Px(16.0)), | |
| margin: UiRect::all(Val::Px(12.0)), |
For consistency with other examples with top-left instructions
|
Checked and working with an 8Bitdo Ultimate on Linux. D-pad and left stick both navigate, I presume because of whatever mode the controller is in. |
b00e303 to
e5d7cda
Compare
# Objective Gamepad / directional navigation needs an example, for both teaching and testing purposes. ## Solution - Add a simple grid-based example. - Fix an intermittent panic caused by a race condition with bevy_a11y - Clean up small issues noticed in bevy_input_focus  ## To do: this PR - [x] figure out why "enter" isn't doing anything - [x] change button color on interaction rather than printing - [x] add on-screen directions - [x] move to an asymmetric grid to catch bugs - [x] ~~fix colors not resetting on button press~~ lol this is mostly just a problem with hacking `Interaction` for this - [x] swap to using observers + bubbling, rather than `Interaction` ## To do: future work - when I increase the button size, such that there is no line break, the text on the buttons is no longer centered :( EDIT: this is bevyengine#16783 - add gamepad stick navigation - add tools to find the nearest populated quadrant to make diagonal inputs work - add a `add_edges` method to `DirectionalNavigationMap` - add a `add_grid` method to `DirectionalNavigationMap` - make the example's layout more complex and realistic - add tools to automatically generate this list - add button shake on failed navigation rather than printing an error - make Pressed events easier to mock: default fields, PointerId::Focus ## Testing `cargo run --example directional_navigation` --------- Co-authored-by: Rob Parrett <robparrett@gmail.com>

Objective
Gamepad / directional navigation needs an example, for both teaching and testing purposes.
Solution
To do: this PR
fix colors not resetting on button presslol this is mostly just a problem with hackingInteractionfor thisInteractionTo do: future work
Text2dandTextSpanis not center-aligned whenJustifyText::Centeris specified. #16783add_edgesmethod toDirectionalNavigationMapadd_gridmethod toDirectionalNavigationMapTesting
cargo run --example directional_navigation