1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::{unit::*, Style, StyleUpdater};
#[derive(Clone, Debug, PartialEq, Display)]
pub enum Gap {
    Value(LengthPercent),
    #[display(fmt = "{} {}", _0, _1)]
    RowColumn(LengthPercent, LengthPercent),
}
impl Gap {
    pub fn row(len: impl Into<LengthPercent>) -> Self {
        Gap::RowColumn(len.into(), px(0).into())
    }
    pub fn column(len: impl Into<LengthPercent>) -> Self {
        Gap::RowColumn(px(0).into(), len.into())
    }
}
impl<T> From<T> for Gap
where
    T: Into<LengthPercent>,
{
    fn from(source: T) -> Self {
        Gap::Value(source.into())
    }
}
impl<T1, T2> From<(T1, T2)> for Gap
where
    T1: Into<LengthPercent>,
    T2: Into<LengthPercent>,
{
    fn from((row, col): (T1, T2)) -> Self {
        let row = row.into();
        let col = col.into();
        Gap::RowColumn(row, col)
    }
}
impl StyleUpdater for Gap {
    fn update_style(self, style: Style) -> Style {
        style.insert("gap", self)
    }
}