use crate::core::Vec2D;
#[derive(Debug, Clone, Copy)]
pub enum TextAlign {
Begin,
Centered,
End,
}
impl TextAlign {
#[must_use]
pub const fn apply_to(&self, pos: i64, text_length: i64) -> i64 {
match self {
Self::Begin => pos,
Self::Centered => pos - text_length / 2,
Self::End => pos - text_length,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct TextAlign2D {
x: TextAlign,
y: TextAlign,
}
impl Default for TextAlign2D {
fn default() -> Self {
Self::new(TextAlign::Begin, TextAlign::Begin)
}
}
impl TextAlign2D {
pub const CENTERED: Self = Self::new(TextAlign::Centered, TextAlign::Centered);
#[must_use]
pub const fn new(x_align: TextAlign, y_align: TextAlign) -> Self {
Self {
x: x_align,
y: y_align,
}
}
#[must_use]
pub const fn apply_to(&self, pos: Vec2D, text_block_size: Vec2D) -> Vec2D {
Vec2D::new(
self.x.apply_to(pos.x, text_block_size.x),
self.y.apply_to(pos.y, text_block_size.y),
)
}
}