leftwm_layouts/geometry/
flip.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents the four states an object can be in,
4/// if it can be flipped horizontally and vertically.
5#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6pub enum Flip {
7    /// Nothing is flipped at all
8    ///
9    /// ```txt
10    ///     +---------+
11    ///     |A       B|
12    ///     |         |
13    ///     |C       D|
14    ///     +---------+
15    /// ```
16    #[default]
17    None,
18
19    /// Flipped on the horizontal axis
20    ///
21    /// ```txt
22    ///     +---------+
23    ///     |C       D|
24    /// >- -|- - - - -|- -<
25    ///     |A       B|
26    ///     +---------+
27    /// ```
28    Horizontal,
29
30    /// Flipped on the vertical axis
31    ///
32    /// ```txt
33    ///          v
34    ///          |    
35    ///     +---------+
36    ///     |B   |   A|
37    ///     |    |    |
38    ///     |D   |   C|
39    ///     +---------+
40    ///          |
41    ///          ^
42    /// ```
43    Vertical,
44
45    /// Flipped on horizontal and vertical axis
46    ///
47    /// ```txt
48    ///          v
49    ///          |
50    ///     +---------+
51    ///     |D   |   C|
52    /// >- -|- - + - -|- -<
53    ///     |B   |   A|
54    ///     +---------+
55    ///          |
56    ///          ^
57    /// ```
58    Both,
59}
60
61impl Flip {
62    /// Indicates whether the variant is flipped horizontally, independent of vertical
63    pub fn is_flipped_horizontal(&self) -> bool {
64        matches!(self, Self::Horizontal | Self::Both)
65    }
66
67    /// Indicates whether the variant is flipped vertically, independent of horizontal
68    pub fn is_flipped_vertical(&self) -> bool {
69        matches!(self, Self::Vertical | Self::Both)
70    }
71
72    /// Returns the resulting [`Flip`] state when flipped horizontally
73    #[must_use]
74    pub fn toggle_horizontal(&self) -> Flip {
75        match self {
76            Self::None => Self::Horizontal,
77            Self::Horizontal => Self::None,
78            Self::Vertical => Self::Both,
79            Self::Both => Self::Vertical,
80        }
81    }
82
83    /// Returns the resulting [`Flip`] state when flipped vertically
84    #[must_use]
85    pub fn toggle_vertical(&self) -> Flip {
86        match self {
87            Self::None => Self::Vertical,
88            Self::Horizontal => Self::Both,
89            Self::Vertical => Self::None,
90            Self::Both => Self::Horizontal,
91        }
92    }
93}