use bevy::prelude::*;
const DEFAULT_BUTTON_WIDTH: Val = Val::Px(400.0);
const DEFAULT_BUTTON_HEIGHT: Val = Val::Px(60.0);
#[derive(Component, Default)]
pub struct UiButtonData {
pub id: usize,
pub payload: Option<String>,
}
#[derive(Bundle)]
pub struct UiButton {
node: Node,
data: UiButtonData,
background_color: BackgroundColor,
marker: Button,
}
impl Default for UiButton {
fn default() -> Self {
Self {
node: Node {
width: DEFAULT_BUTTON_WIDTH,
height: DEFAULT_BUTTON_HEIGHT,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
data: UiButtonData::default(),
background_color: BackgroundColor::DEFAULT,
marker: Button,
}
}
}
impl UiButton {
pub fn rectangle() -> Self {
Self::default()
}
pub fn square() -> Self {
Self::default().width(DEFAULT_BUTTON_HEIGHT)
}
pub fn background_color(mut self, color: Color) -> Self {
self.background_color = color.into();
self
}
pub fn width(mut self, width: Val) -> Self {
self.node.width = width;
self
}
pub fn height(mut self, height: Val) -> Self {
self.node.height = height;
self
}
pub fn id(mut self, id: usize) -> Self {
self.data.id = id;
self
}
pub fn payload(mut self, payload: &str) -> Self {
self.data.payload = Some(payload.into());
self
}
}