Skip to content

Migrate widgets to use observe function. #460

@Freyja-moth

Description

@Freyja-moth

Bevy 0.17 added the observe function using a bundle effect which makes it easier to add observers to nest hierarchies.

So far the only place that could use this that I've found is

Children::spawn(SpawnWith(|parent: &mut ChildSpawner| {

Which could now be done as

(
    Name::new("Button"),
    Node::default(),
    children![
        Name::new("Button Inner"),
        Button,
        BackgroundColor(BUTTON_BACKGROUND),
        InteractionPalette {
            none: BUTTON_BACKGROUND,
            hovered: BUTTON_HOVERED_BACKGROUND,
            pressed: BUTTON_PRESSED_BACKGROUND,
        },
        button_bundle,
        observe(action),
        children![(
            Name::new("Button Text"),
            Text(text),
            TextFont::from_font_size(40.0),
            TextColor(BUTTON_TEXT),
            // Don't bubble picking events from the text up to the button.
            Pickable::IGNORE,
        )],
    )]
)

But there may be more that I'm missing

This will require enabling the experimental_bevy_ui_widgets feature on bevy though which may not be desirable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-Code-QualityA section of code that is hard to understand or changeX-ContentiousThere are nontrivial implications that should be thought through

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions