bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Core button widget

Open viridia opened this issue 7 months ago • 1 comments

Objective

Part of #19236

Solution

Adds a new bevy_core_widgets crate containing headless widget implementations. This PR adds a single CoreButton widget, more widgets to be added later once this is approved.

Testing

There's an example, ui/core_widgets.

viridia avatar May 25 '25 22:05 viridia

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

github-actions[bot] avatar May 25 '25 22:05 github-actions[bot]

From @cart on Discord.

Another thing thats come up with @DreamerTalin's core widget work (in addition to ⁠Marker Component Change Queries): we now have increased need for something like @doot's static multi-event-listening proposal: https://github.com/bevyengine/bevy/pull/14674

While the newer dynamic proposal is flexible, I think we will want the ease of use / directness of the static API, as these are likely to be defined "in context" next to widgets. Ex: currently this requires six different identical observers, which isn't defensible:

fn on_button_change(
    trigger: Trigger<(
        OnAdd<Pressed>,
        OnRemove<Pressed>,
        OnAdd<InteractionDisabled>,
        OnRemove<InteractionDisabled>,
        OnInsert<Hovered>,
    )>,
    mut buttons: Query<
        (
            Has<Depressed>,
            &IsHovered,
            Has<InteractionDisabled>,
            &mut BackgroundColor,
            &mut BorderColor,
            &Children,
        ),
        With<DemoButton>,
    >,
    mut text_query: Query<&mut Text>,
) {
    if let Ok((pressed, hovered, disabled, mut color, mut border_color, children)) =
        buttons.get_mut(trigger.target())
    {
        let mut text = text_query.get_mut(children[0]).unwrap();
        set_button_style(
            disabled,
            hovered.get(),
            pressed,
            &mut color,
            &mut border_color,
            &mut text,
        );
    }
}

Notice that I switched to Trigger<OnAdd<Pressed>> instead of Trigger<OnAdd, Pressed>, as the current interface only supports a single component-target, which doesn't lend itself to expressing multiple events

To effectively support things like the set_button_style scenario, I think we need need to land one or both of ⁠Multi-Event Observers and ⁠Marker Component Change Queries

I'd like to merge so we can iterate. I think worst case scenario we move it to an experimental module

alice-i-cecile avatar Jun 10 '25 00:06 alice-i-cecile

@alice-i-cecile CI is broken, I don't get why. OnAdd is private?

viridia avatar Jun 10 '25 04:06 viridia

Ah right, lifecycle migration.

viridia avatar Jun 10 '25 04:06 viridia