use bevy::reflect::Reflect;
#[derive(Debug, Default, Reflect, Clone, Copy, PartialEq)]
pub enum Units {
Pixels(f32),
Percentage(f32),
#[default]
Auto,
}
impl From<f32> for Units {
fn from(value: f32) -> Self {
Units::Pixels(value)
}
}
impl Units {
pub fn value_or(&self, auto: f32) -> f32 {
match self {
Units::Pixels(pixels) => *pixels,
Units::Percentage(percentage) => percentage / 100.0,
Units::Auto => auto,
}
}
pub fn is_pixels(&self) -> bool {
matches!(self, Units::Pixels(_))
}
pub fn is_percentage(&self) -> bool {
matches!(self, Units::Percentage(_))
}
pub fn is_auto(&self) -> bool {
matches!(self, Units::Auto)
}
}