Skip to main content

tree_table/types/
cell_align.rs

1#[cfg_attr(feature = "tsify", derive(tsify::Tsify))]
2#[cfg_attr(feature = "tsify", tsify(from_wasm_abi))]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum CellAlign {
6    #[default]
7    General, // left for text, right for numbers
8
9    // Top row
10    TopLeft,
11    TopCenter,
12    TopRight,
13
14    // Middle row
15    MiddleLeft,
16    MiddleCenter,
17    MiddleRight,
18
19    // Bottom row
20    BottomLeft,
21    BottomCenter,
22    BottomRight,
23
24    // Special
25    Justify,
26    Fill,
27}
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum HorizontalAlign {
31    General,
32    Left,
33    Center,
34    Right,
35    Justify,
36    Fill,
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum VerticalAlign {
41    Top,
42    Middle,
43    Bottom,
44    Justify,
45}
46
47impl CellAlign {
48    pub fn horizontal(&self) -> HorizontalAlign {
49        match self {
50            CellAlign::General
51            | CellAlign::TopLeft
52            | CellAlign::MiddleLeft
53            | CellAlign::BottomLeft => HorizontalAlign::Left,
54            CellAlign::TopCenter | CellAlign::MiddleCenter | CellAlign::BottomCenter => {
55                HorizontalAlign::Center
56            }
57            CellAlign::TopRight | CellAlign::MiddleRight | CellAlign::BottomRight => {
58                HorizontalAlign::Right
59            }
60            CellAlign::Justify => HorizontalAlign::Justify,
61            CellAlign::Fill => HorizontalAlign::Fill,
62        }
63    }
64
65    pub fn vertical(&self) -> VerticalAlign {
66        match self {
67            CellAlign::TopLeft | CellAlign::TopCenter | CellAlign::TopRight => VerticalAlign::Top,
68            CellAlign::MiddleLeft | CellAlign::MiddleCenter | CellAlign::MiddleRight => {
69                VerticalAlign::Middle
70            }
71            CellAlign::BottomLeft | CellAlign::BottomCenter | CellAlign::BottomRight => {
72                VerticalAlign::Bottom
73            }
74            _ => VerticalAlign::Top,
75        }
76    }
77}