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    fn default() -> Self {
68        Self::Start
69    }
70}
71
72/// Specifies the alignment of a child within its parent container, both vertically and horizontally.
73/// Useful for positioning a single child inside a container, such as in a [`crate::boxed::boxed`] component.
74///
75/// # Variants
76/// - `TopStart`: Top-left corner.
77/// - `TopCenter`: Top edge, centered horizontally.
78/// - `TopEnd`: Top-right corner.
79/// - `CenterStart`: Center vertically, left edge.
80/// - `Center`: Center both vertically and horizontally.
81/// - `CenterEnd`: Center vertically, right edge.
82/// - `BottomStart`: Bottom-left corner.
83/// - `BottomCenter`: Bottom edge, centered horizontally.
84/// - `BottomEnd`: Bottom-right corner.
85#[derive(Debug, Clone, Copy, PartialEq)]
86pub enum Alignment {
87    /// Top-left corner.
88    TopStart,
89    /// Top edge, centered horizontally.
90    TopCenter,
91    /// Top-right corner.
92    TopEnd,
93    /// Center vertically, left edge.
94    CenterStart,
95    /// Center both vertically and horizontally.
96    Center,
97    /// Center vertically, right edge.
98    CenterEnd,
99    /// Bottom-left corner.
100    BottomStart,
101    /// Bottom edge, centered horizontally.
102    BottomCenter,
103    /// Bottom-right corner.
104    BottomEnd,
105}
106
107impl Default for Alignment {
108    /// Returns [`Alignment::TopStart`] as the default value.
109    ///
110    /// # Example
111    ///
112    /// ```
113    /// use tessera_ui_basic_components::alignment::Alignment;
114    /// assert_eq!(Alignment::default(), Alignment::TopStart);
115    /// ```
116    fn default() -> Self {
117        Self::TopStart
118    }
119}