Skip to main content

cranpose_ui_layout/
axis.rs

1/// A direction of layout or motion: the main axis of a row or a column, the
2/// axis along which a scroller, a lazy list or a pager moves, and the axis a
3/// nested scroll reports.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum Axis {
6    /// Left to right: a row's main axis, or content that moves left and right.
7    Horizontal,
8
9    /// Top to bottom: a column's main axis, or content that moves up and down.
10    Vertical,
11}
12
13impl Axis {
14    /// Returns the opposite axis.
15    #[inline]
16    pub fn cross_axis(self) -> Self {
17        match self {
18            Self::Horizontal => Self::Vertical,
19            Self::Vertical => Self::Horizontal,
20        }
21    }
22
23    /// Returns true if this is the horizontal axis.
24    #[inline]
25    pub fn is_horizontal(self) -> bool {
26        matches!(self, Self::Horizontal)
27    }
28
29    /// Returns true if this is the vertical axis.
30    #[inline]
31    pub fn is_vertical(self) -> bool {
32        matches!(self, Self::Vertical)
33    }
34}
35
36#[cfg(test)]
37#[path = "tests/axis_tests.rs"]
38mod tests;