gemini_engine/ascii/
alignment.rs1use crate::core::Vec2D;
2
3#[derive(Debug, Clone, Copy)]
5pub enum TextAlign {
6 Begin,
8 Centered,
10 End,
12}
13
14impl TextAlign {
15 #[must_use]
17 pub const fn apply_to(&self, pos: i64, text_length: i64) -> i64 {
18 match self {
19 Self::Begin => pos,
20 Self::Centered => pos - text_length / 2,
21 Self::End => pos - text_length,
22 }
23 }
24}
25
26#[derive(Debug, Clone, Copy)]
28pub struct TextAlign2D {
29 x: TextAlign,
31 y: TextAlign,
33}
34
35impl Default for TextAlign2D {
36 fn default() -> Self {
37 Self::new(TextAlign::Begin, TextAlign::Begin)
38 }
39}
40
41impl TextAlign2D {
42 pub const CENTERED: Self = Self::new(TextAlign::Centered, TextAlign::Centered);
44
45 #[must_use]
47 pub const fn new(x_align: TextAlign, y_align: TextAlign) -> Self {
48 Self {
49 x: x_align,
50 y: y_align,
51 }
52 }
53
54 #[must_use]
56 pub const fn apply_to(&self, pos: Vec2D, text_block_size: Vec2D) -> Vec2D {
57 Vec2D::new(
58 self.x.apply_to(pos.x, text_block_size.x),
59 self.y.apply_to(pos.y, text_block_size.y),
60 )
61 }
62}