use bevy_ecs::{component::Component, reflect::ReflectComponent};1use bevy_math::Vec2;2use bevy_reflect::{std_traits::ReflectDefault, Reflect};34/// The maximum width and height of text. The text will wrap according to the specified size.5///6/// Characters out of the bounds after wrapping will be truncated. Text is aligned according to the7/// specified [`Justify`](crate::text::Justify).8///9/// Note: only characters that are completely out of the bounds will be truncated, so this is not a10/// reliable limit if it is necessary to contain the text strictly in the bounds. Currently this11/// component is mainly useful for text wrapping only.12#[derive(Component, Copy, Clone, Debug, Reflect)]13#[reflect(Component, Default, Debug, Clone)]14pub struct TextBounds {15/// The maximum width of text in logical pixels.16/// If `None`, the width is unbounded.17pub width: Option<f32>,18/// The maximum height of text in logical pixels.19/// If `None`, the height is unbounded.20pub height: Option<f32>,21}2223impl Default for TextBounds {24#[inline]25fn default() -> Self {26Self::UNBOUNDED27}28}2930impl TextBounds {31/// Unbounded text will not be truncated or wrapped.32pub const UNBOUNDED: Self = Self {33width: None,34height: None,35};3637/// Creates a new `TextBounds`, bounded with the specified width and height values.38#[inline]39pub const fn new(width: f32, height: f32) -> Self {40Self {41width: Some(width),42height: Some(height),43}44}4546/// Creates a new `TextBounds`, bounded with the specified width value and unbounded on height.47#[inline]48pub const fn new_horizontal(width: f32) -> Self {49Self {50width: Some(width),51height: None,52}53}5455/// Creates a new `TextBounds`, bounded with the specified height value and unbounded on width.56#[inline]57pub const fn new_vertical(height: f32) -> Self {58Self {59width: None,60height: Some(height),61}62}63}6465impl From<Vec2> for TextBounds {66#[inline]67fn from(v: Vec2) -> Self {68Self::new(v.x, v.y)69}70}717273