tessera_ui_basic_components/
alignment.rs

1//! Defines alignment options for layout components.
2
3/// Specifies how children are placed along the main axis (the direction of layout)
4/// in layout containers such as [`crate::row::row`] or [`crate::column::column`].
5///
6/// # Variants
7///
8/// - `Start`: Place children at the start (left or top).
9/// - `Center`: Center children along the main axis.
10/// - `End`: Place children at the end (right or bottom).
11/// - `SpaceEvenly`: Evenly distribute children, including space at the start and end.
12/// - `SpaceBetween`: Evenly distribute children, with no space at the start and end.
13/// - `SpaceAround`: Evenly distribute children, with half-space at the start and end.
14#[derive(Debug, Clone, Copy, PartialEq)]
15pub enum MainAxisAlignment {
16    /// Place children at the start (left or top).
17    Start,
18    /// Center children along the main axis.
19    Center,
20    /// Place children at the end (right or bottom).
21    End,
22    /// Evenly distribute children, including space at the start and end.
23    SpaceEvenly,
24    /// Evenly distribute children, with no space at the start and end.
25    SpaceBetween,
26    /// Evenly distribute children, with half-space at the start and end.
27    SpaceAround,
28}
29
30impl Default for MainAxisAlignment {
31    /// Returns [`MainAxisAlignment::Start`] as the default value.
32    ///
33    /// # Example
34    ///
35    /// ```
36    /// use tessera_ui_basic_components::alignment::MainAxisAlignment;;
37    /// assert_eq!(MainAxisAlignment::default(), MainAxisAlignment::Start);
38    /// ```
39    fn default() -> Self {
40        Self::Start
41    }
42}
43
44/// Specifies how children are aligned along the cross axis (perpendicular to the layout direction)
45/// in layout containers such as [`crate::row::row`] or [`crate::column::column`].
46///
47/// # Variants
48///
49/// - `Start`: Align children to the start (left or top).
50/// - `Center`: Center children along the cross axis.
51/// - `End`: Align children to the end (right or bottom).
52/// - `Stretch`: Stretch children to fill the cross axis.
53#[derive(Debug, Clone, Copy, PartialEq)]
54pub enum CrossAxisAlignment {
55    /// Align children to the start (left or top).
56    Start,
57    /// Center children along the cross axis.
58    Center,
59    /// Align children to the end (right or bottom).
60    End,
61    /// Stretch children to fill the entire cross axis.
62    Stretch,
63}
64
65impl Default for CrossAxisAlignment {
66    /// Returns [`CrossAxisAlignment::Start`] as the default value.
67    ///
68    /// # Example
69    /// ```rust,ignore
70    /// use tessera_ui_basic_components::CrossAxisAlignment;
71    /// assert_eq!(CrossAxisAlignment::default(), CrossAxisAlignment::Start);
72    /// ```
73    fn default() -> Self {
74        Self::Start
75    }
76}
77
78/// Specifies the alignment of a child within its parent container, both vertically and horizontally.
79/// Useful for positioning a single child inside a container, such as in a [`crate::boxed::boxed`] component.
80///
81/// # Variants
82/// - `TopStart`: Top-left corner.
83/// - `TopCenter`: Top edge, centered horizontally.
84/// - `TopEnd`: Top-right corner.
85/// - `CenterStart`: Center vertically, left edge.
86/// - `Center`: Center both vertically and horizontally.
87/// - `CenterEnd`: Center vertically, right edge.
88/// - `BottomStart`: Bottom-left corner.
89/// - `BottomCenter`: Bottom edge, centered horizontally.
90/// - `BottomEnd`: Bottom-right corner.
91#[derive(Debug, Clone, Copy, PartialEq)]
92pub enum Alignment {
93    /// Top-left corner.
94    TopStart,
95    /// Top edge, centered horizontally.
96    TopCenter,
97    /// Top-right corner.
98    TopEnd,
99    /// Center vertically, left edge.
100    CenterStart,
101    /// Center both vertically and horizontally.
102    Center,
103    /// Center vertically, right edge.
104    CenterEnd,
105    /// Bottom-left corner.
106    BottomStart,
107    /// Bottom edge, centered horizontally.
108    BottomCenter,
109    /// Bottom-right corner.
110    BottomEnd,
111}
112
113impl Default for Alignment {
114    /// Returns [`Alignment::TopStart`] as the default value.
115    ///
116    /// # Example
117    ///
118    /// ```
119    /// use tessera_ui_basic_components::alignment::Alignment;
120    /// assert_eq!(Alignment::default(), Alignment::TopStart);
121    /// ```
122    fn default() -> Self {
123        Self::TopStart
124    }
125}