cranpose_ui_layout/axis.rs
1/// Represents the primary axis of flex layout (Row or Column).
2///
3/// This enum is used by FlexMeasurePolicy to determine which direction
4/// is the main axis (where children are laid out) and which is the cross axis
5/// (where children are aligned).
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Axis {
8 /// Horizontal main axis (Row).
9 /// Main axis: left to right
10 /// Cross axis: top to bottom
11 Horizontal,
12
13 /// Vertical main axis (Column).
14 /// Main axis: top to bottom
15 /// Cross axis: left to right
16 Vertical,
17}
18
19impl Axis {
20 /// Returns the opposite axis.
21 #[inline]
22 pub fn cross_axis(self) -> Self {
23 match self {
24 Axis::Horizontal => Axis::Vertical,
25 Axis::Vertical => Axis::Horizontal,
26 }
27 }
28
29 /// Returns true if this is the horizontal axis.
30 #[inline]
31 pub fn is_horizontal(self) -> bool {
32 matches!(self, Axis::Horizontal)
33 }
34
35 /// Returns true if this is the vertical axis.
36 #[inline]
37 pub fn is_vertical(self) -> bool {
38 matches!(self, Axis::Vertical)
39 }
40}