Skip to main content

photon_ui/layout/
direction.rs

1/// Layout direction.
2#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
3pub enum Direction {
4    /// Arrange children left-to-right.
5    Horizontal,
6    /// Arrange children top-to-bottom.
7    #[default]
8    Vertical,
9}
10
11impl Direction {
12    /// Return the direction orthogonal to this one.
13    pub const fn perpendicular(self) -> Self {
14        match self {
15            | Self::Horizontal => Self::Vertical,
16            | Self::Vertical => Self::Horizontal,
17        }
18    }
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    #[test]
26    fn direction_perpendicular() {
27        assert_eq!(Direction::Horizontal.perpendicular(), Direction::Vertical);
28        assert_eq!(Direction::Vertical.perpendicular(), Direction::Horizontal);
29    }
30
31    #[test]
32    fn direction_default() {
33        assert_eq!(Direction::default(), Direction::Vertical);
34    }
35}