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