//! This example illustrates how to create buttons with their textures sliced //! and kept in proportion instead of being stretched by the button dimensions. //! //! It uses the `bevy_ui_widgets` headless [`Button`] widget. The button's hover and press //! state is tracked by the `Hovered` and `Pressed` components; a `Changed`-based system //! updates the sliced image's tint and label to match. use bevy::{ color::palettes::css::{GOLD, ORANGE}, picking::hover::Hovered, platform::collections::HashSet, prelude::*, ui::{widget::NodeImageMode, Pressed}, ui_widgets::Button, }; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_systems(Update, button_system) .run(); } /// Updates each button's sliced image tint and label whenever its `Pressed` or `Hovered` /// state changes. /// /// `Hovered` always exists on the button, so `Ref::is_changed` catches hover transitions and /// the insertion of `Pressed`. Removal of `Pressed` is not reported by change detection, so we /// also restyle any button that just had `Pressed` removed this frame. fn button_system( mut buttons: Query< ( Entity, Option>, Ref, &mut ImageNode, &Children, ), With