bevy/crates/bevy_winit/src
Alice Cecile 145f5f4394
Add a simple directional UI navigation example (#17224)
# 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


![image](https://github.com/user-attachments/assets/3a924255-0cd6-44a5-9bb7-b2c400a22d7e)

## 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
https://github.com/bevyengine/bevy/issues/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>
2025-01-09 21:15:28 +00:00
..
accessibility.rs Add a simple directional UI navigation example (#17224) 2025-01-09 21:15:28 +00:00
converters.rs Expose text field from winit in KeyboardInput (#16864) 2024-12-17 22:42:54 +00:00
cursor.rs Remove tracing re-export from bevy_utils (#17161) 2025-01-05 23:06:34 +00:00
lib.rs bevy_winit: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17232) 2025-01-09 06:29:29 +00:00
state.rs Update winit_runner to use spawn_app for wasm32 target (#16630) 2025-01-06 23:21:24 +00:00
system.rs Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
winit_config.rs Remove everything except Instant from bevy_utils::time (#17158) 2025-01-05 20:36:08 +00:00
winit_monitors.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
winit_windows.rs Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00