Skip to main content

photon_ui/layout/
flex.rs

1/// How excess space is distributed when layout constraints are satisfied.
2#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
3pub enum Flex {
4    /// Excess space goes into the last element (ratatui legacy behavior).
5    Legacy,
6    /// Align items to the start.
7    #[default]
8    Start,
9    /// Align items to the end.
10    End,
11    /// Center items.
12    Center,
13    /// Space between items, none at edges.
14    SpaceBetween,
15    /// Space around items.
16    SpaceAround,
17    /// Even space before, between, and after items.
18    SpaceEvenly,
19}
20
21impl Flex {
22    /// Returns `true` if this is [`Flex::Legacy`].
23    pub const fn is_legacy(self) -> bool {
24        matches!(self, Self::Legacy)
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn flex_default() {
34        assert_eq!(Flex::default(), Flex::Start);
35    }
36
37    #[test]
38    fn flex_is_legacy() {
39        assert!(Flex::Legacy.is_legacy());
40        assert!(!Flex::Start.is_legacy());
41        assert!(!Flex::End.is_legacy());
42        assert!(!Flex::Center.is_legacy());
43        assert!(!Flex::SpaceBetween.is_legacy());
44        assert!(!Flex::SpaceAround.is_legacy());
45        assert!(!Flex::SpaceEvenly.is_legacy());
46    }
47}