use bevy_ecs::prelude::*;
use super::color::Color;
use super::rect::Rect;
#[derive(Component, Clone, Copy, Debug, Default)]
pub struct Position {
pub x: f32,
pub y: f32,
}
#[derive(Component, Clone, Copy, Debug)]
pub struct Size {
pub width: f32,
pub height: f32,
}
impl Position {
pub fn rect(&self, size: &Size) -> Rect {
Rect::new(self.x, self.y, size.width, size.height)
}
}
impl From<Rect> for (Position, Size) {
fn from(rect: Rect) -> Self {
(
Position {
x: rect.x,
y: rect.y,
},
Size {
width: rect.width,
height: rect.height,
},
)
}
}
#[derive(Component, Clone, Copy, Debug)]
pub struct Background(pub Color);
#[derive(Component, Clone, Debug)]
pub struct Label(pub String);
#[derive(Component, Clone, Copy, Debug)]
pub struct LabelSize(pub f32);
#[derive(Component, Clone, Copy, Debug)]
pub struct TextColor(pub Color);
impl Default for TextColor {
fn default() -> Self {
Self(Color::WHITE)
}
}
#[derive(Component, Clone, Copy, Debug)]
pub struct Icon {
pub path: &'static str,
pub color: Color,
}
impl Icon {
pub fn new(path: &'static str) -> Self {
Self {
path,
color: Color::WHITE,
}
}
pub fn tinted(path: &'static str, color: Color) -> Self {
Self { path, color }
}
}
#[derive(Component, Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum LabelAlign {
#[default]
Center,
Left,
}
#[derive(Component, Clone, Copy, Debug, Default)]
pub struct ButtonIcons {
pub leading: Option<&'static str>,
pub trailing: Option<&'static str>,
}
impl ButtonIcons {
pub fn leading(icon: &'static str) -> Self {
Self {
leading: Some(icon),
trailing: None,
}
}
}