diff --git a/src/widgets/machines.rs b/src/widgets/machines.rs index a5b26f6..60486ad 100644 --- a/src/widgets/machines.rs +++ b/src/widgets/machines.rs @@ -3,7 +3,7 @@ use bevy::{color::palettes::css::*, prelude::*, ui::Val::*}; use crate::{ game::machines::*, resources::UiTheme, - widgets::{machine_ui_base, spawn_big_red_button}, + widgets::{BigRedButton, machine_ui_base}, }; impl CuttingMachine { @@ -42,7 +42,7 @@ impl CuttingMachine { BackgroundColor(DARK_GRAY.into()), Pickable::default(), )) - .with_children(|cmds| spawn_big_red_button(cmds, "CUT")); + .with_children(|cmds| BigRedButton::spawn_big_red_button(cmds, "CUT")); }); } } @@ -82,7 +82,7 @@ impl RotatingMachine { BackgroundColor(DARK_GRAY.into()), Pickable::default(), )) - .with_children(|cmds| spawn_big_red_button(cmds, "TURN")); + .with_children(|cmds| BigRedButton::spawn_big_red_button(cmds, "TURN")); }); } } diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index e0ee714..f4edd26 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -82,86 +82,92 @@ fn machine_ui_base(commands: &mut Commands, header: impl Into, theme: &U root_pane } -// TODO: Hook up action handling (callback? Observer? Some other weird component?) -fn spawn_big_red_button(commands: &mut ChildSpawnerCommands, text: impl Into) { - let mut builder = commands.spawn(( - Button, - Node { - width: Px(60.0), - height: Px(60.0), - aspect_ratio: Some(1.0), +/// The "Big Red Button" that makes a machine perform it's action. +#[derive(Component)] +pub struct BigRedButton; - // Why is it "align_items" to center the text vertically, - // but "justify_*content*" to center it horizontally? - align_items: AlignItems::Center, - // align_content: AlignContent::Center, - justify_content: JustifyContent::Center, - border: UiRect::all(Px(2.0)), - ..Default::default() - }, - BackgroundColor(RED.into()), - BorderColor(DARK_RED.into()), - BorderRadius::MAX, - children![ - Text::new(text), - TextColor(WHITE.into()), - TextShadow::default(), - ], - )); - builder.observe(button_hover_start); - builder.observe(button_hover_stop); - builder.observe(button_press_start); - builder.observe(button_press_stop); -} +impl BigRedButton { + // TODO: Hook up action handling (callback? Observer? Some other weird component?) + fn spawn_big_red_button(commands: &mut ChildSpawnerCommands, text: impl Into) { + let mut builder = commands.spawn(( + Button, + Node { + width: Px(60.0), + height: Px(60.0), + aspect_ratio: Some(1.0), -/// Re-color the button when a pointer passes over it -fn button_hover_start( - event: Trigger>, - // Get button background and border colors so we can change them. - // Filter for *changed* interactions, and only entities with a [`Button`] - mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With