UI settings panel helpers for examples
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
This was discussed in #25032 - the suggestion is controversial, but I wanted to document the idea anyway.
A lot of examples in Bevy have minimal UI (either buttons or keyboard shortcuts) that lets you adjust certain parameters and options. One way to surface these options is to use BSN to spawn a UI scene with feathers buttons, checkboxes, and number inputs representing the various parameters; however then we also need to write observers to listen to events from those widgets and update the example's settings - the basic data binding problem. Doing so requires a substantial degree of boilerplate which can, in some cases, distract from the purpose of the example, which is to teach the user about rendering or audio or some such, not about how to build a UI.
Frameworks like `three.js` provide helper libraries which make it easy to generate a panel of adjustable parameters. `bevy_egui` provides a similar capability.
## What solution would you like?
We could use Bevy's reflection capabilities. The user starts by defining a `Resource` that contains all of the tweakable knobs for the example:
```rust
#[derive(Resource, Reflect)]
struct Settings {
#[reflect(@Caption("Animation speed"), @Range(0.0..100.0))]
pub animation_speed: f32,
#[reflect(@Caption("Enable anti-aliasing"))]
pub anti_alias: bool,
}
```
Given this, we can use reflection to automatically generate the controls for the floating panel.
The reflection-based annotations can be extended to support:
* enums
* game modes
* sub-groups or expandable folders
The example would still need to read properties from the resource and update the state of the example, although perhaps this could be simplified as well. In either case, most of the complexity of the UI code would be external to the example file.
## What alternative(s) have you considered?
Manually implement the data binding without a helper.
@alice-i-cecile @kfc35 @IceSentry
Contributor guide
Research direction
Start by reading the discussion in #25032 and the proposed Resource/Reflect example in this issue. No files, tests, or implementation entry points are identified. The work is done when the project has an agreed design and a working reflection-based settings panel supporting the required controls without per-example UI boilerplate.
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
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100