Making bevy_ui_widgets input-mapper friendly
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
I'm currently experimenting with using a gamepad to control the widgets in bevy_ui_widgets. My scheme involves having conditional input contexts that are predicated on what kind of widget has focus - so for example, we can have a `SliderFocused` input context which is active when a slider has focus, and this input context contains actions and bindings which will generate events that the slider can accept.
There has already been some work done on this in `bevy_ui_widgets` but it is currently unused. For example, the `SetSliderValue` event allows a slider to be remote-controlled via observer events, but nothing currently triggers these events.
There are a couple missing pieces here. One is a way to identify what type of widget currently has focus. It's certainly possible to do this in a one-off fashion - "does the currently focused widget have a `Slider` component?" - but it would be better if widgets had a stable id. This id represents a promise to honor a particular kind of contract: that the widget will respond to a particular set of events.
There's also an open question about making more of the widgets remote controlled. The `SetSliderValue` event was based on a guess, but that guess might be wrong. There are different ways that this problem could be approached.
Take `Button` for example. It's trivial to simulate a click on a button by posting an `Activate` event on the button entity - the same event that is emitted when the button is clicked. However, what if we also wanted the button to show the `Pressed` state when the gamepad button is held down? There are different ways this could be accomplished, all of which are performed by action handlers on the input mapper:
* Directly reach into the button entity and insert a `Pressed` component, and remove it later.
* Send fake Picking events to the button, as if it were being clicked by a mouse.
* Define special `RemotePress` and `RemoteRelease` events which are dispatched to the button from the input mapper.
@alice-i-cecile @kfc35 @ickshonpe
Contributor guide
Research direction
Start by reading the existing bevy_ui_widgets handling for SetSliderValue and the Button paths involving Activate, Pressed, and Picking events. Clarify with maintainers which widget contracts and input-mapper behavior are in scope; done requires an agreed stable focus identity and defined remote-control behavior for the selected widgets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100