You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
Rust
58 lines
1.7 KiB
Rust
use crate::prelude::*;
|
|
|
|
/// Menu Plugin; empty struct for Plugin impl
|
|
pub(crate) struct UiPlugin;
|
|
|
|
impl Plugin for UiPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(
|
|
Update,
|
|
button_interaction.run_if(any_component_changed::<Interaction>),
|
|
);
|
|
}
|
|
}
|
|
|
|
fn button_interaction(mut query: Query<(&mut BackgroundColor, &Interaction)>) {
|
|
query.iter_mut().for_each(|(mut bg, i)| match i {
|
|
Interaction::Hovered => bg.0 = Color::ORANGE,
|
|
Interaction::Pressed => bg.0 = Color::GREEN,
|
|
Interaction::None => bg.0 = Color::WHITE,
|
|
});
|
|
}
|
|
|
|
pub(crate) mod button {
|
|
use super::*;
|
|
|
|
pub(crate) struct UiButton {
|
|
pub label: &'static str,
|
|
}
|
|
|
|
impl EntityCommand for UiButton {
|
|
fn apply(self, id: Entity, world: &mut World) {
|
|
let button_text_style = TextStyle {
|
|
color: Color::BLACK,
|
|
font_size: 16.0,
|
|
..default()
|
|
};
|
|
world
|
|
.entity_mut(id)
|
|
.insert(ButtonBundle {
|
|
style: Style {
|
|
margin: UiRect::all(Val::Px(5.0)),
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
border: UiRect::all(Val::Px(1.0)),
|
|
..default()
|
|
},
|
|
border_color: BorderColor(Color::BLACK),
|
|
..default()
|
|
})
|
|
.with_children(|parent| {
|
|
parent.spawn(TextBundle {
|
|
text: Text::from_section(self.label, button_text_style),
|
|
..default()
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|