diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index fbdb5ac..39fa3f2 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -54,7 +54,6 @@ fn machine_ui_base(header: impl Into) -> impl Bundle { // TODO: Text shadow, maybe. I couldn't make it look good. )], ), - CloseButton::bundle(), ], ) } @@ -145,13 +144,13 @@ fn button_press_stop( /// Button marker for closing (despawning) an in-game menu entity. #[derive(Component)] #[require(Button)] -pub struct CloseButton; +pub struct CloseButton(Entity); impl CloseButton { /// Spawn a button that will despawn the top-most node when pressed. - fn bundle() -> impl Bundle { + fn bundle(target: Entity) -> impl Bundle { ( - CloseButton, + CloseButton(target), Node { width: Px(20.0), height: Px(20.0), @@ -214,12 +213,13 @@ impl CloseButton { pub fn press_stop( event: Trigger>, mut commands: Commands, - mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With>, + mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor, &CloseButton)>, ui_theme: Res, ) { - if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) { + if let Ok((mut bg, mut border, CloseButton(target))) = button_colors.get_mut(event.target()) { bg.0 = ui_theme.quiet_bg; border.0 = ui_theme.quiet_border; + commands.entity(*target).despawn(); } } }