Skip to main content

torin/values/
order.rs

1#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2#[derive(PartialEq, Eq, Clone, Debug, Default, Copy)]
3pub enum Order {
4    /// Lay children out in their natural order. This is the default.
5    #[default]
6    Forward,
7    /// Lay children out in reverse order along the direction axis.
8    Backward,
9}
10
11impl Order {
12    /// Use a [`Forward`](Order::Forward) order.
13    pub fn forward() -> Order {
14        Order::Forward
15    }
16
17    /// Use a [`Backward`](Order::Backward) order.
18    pub fn backward() -> Order {
19        Order::Backward
20    }
21
22    /// Whether children are laid out in reverse order.
23    pub fn is_reverse(&self) -> bool {
24        matches!(self, Self::Backward)
25    }
26
27    pub fn pretty(&self) -> String {
28        match self {
29            Self::Forward => "forward".to_string(),
30            Self::Backward => "backward".to_string(),
31        }
32    }
33}