bevy_ui_builders/button/
plugin.rs

1//! Button plugin for Bevy
2
3use bevy::prelude::*;
4use bevy_plugin_builder::define_plugin;
5use super::systems::{
6    handle_hover_scale,
7    handle_hover_brightness,
8    handle_button_interaction,
9    animate_button_transitions,
10    auto_toggle_selectable_buttons,
11    enforce_exclusive_button_groups,
12    update_selection_appearance,
13    apply_selection_colors_immediately,
14};
15use super::types::SelectionChanged;
16
17// Plugin that adds button interaction systems
18define_plugin!(ButtonPlugin {
19    custom_init: |app: &mut App| {
20        // Register selection changed message
21        app.add_message::<SelectionChanged>();
22    },
23    update: [
24        // Selection state management - CHAINED to ensure commands are applied!
25        (
26            // Step 1: Handle button clicks and modify Selected components
27            (enforce_exclusive_button_groups, auto_toggle_selectable_buttons),
28            // Step 2: Update target colors based on Selected/Active (needs Selected changes applied)
29            update_selection_appearance,
30            // Step 3: Apply colors to BackgroundColor/BorderColor
31            apply_selection_colors_immediately,
32        ).chain(),
33
34        // Animation and interaction
35        (handle_button_interaction, animate_button_transitions).chain(),
36
37        // Legacy hover systems
38        (handle_hover_scale, handle_hover_brightness),
39    ]
40});