use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_math::Vec2;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
#[derive(Component, Copy, Clone, Debug, Reflect)]
#[reflect(Component, Default, Debug, Clone)]
pub struct TextBounds {
pub width: Option<f32>,
pub height: Option<f32>,
}
impl Default for TextBounds {
#[inline]
fn default() -> Self {
Self::UNBOUNDED
}
}
impl TextBounds {
pub const UNBOUNDED: Self = Self {
width: None,
height: None,
};
#[inline]
pub const fn new(width: f32, height: f32) -> Self {
Self {
width: Some(width),
height: Some(height),
}
}
#[inline]
pub const fn new_horizontal(width: f32) -> Self {
Self {
width: Some(width),
height: None,
}
}
#[inline]
pub const fn new_vertical(height: f32) -> Self {
Self {
width: None,
height: Some(height),
}
}
}
impl From<Vec2> for TextBounds {
#[inline]
fn from(v: Vec2) -> Self {
Self::new(v.x, v.y)
}
}