summaryrefslogtreecommitdiffstats
path: root/core/src/padding.rs
blob: 083f7eab7edfe0d92b9484624d8140554247ebdf (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
/// An amount of space to pad for each side of a box
#[derive(Debug, Hash, Copy, Clone)]
pub struct Padding {
    /// Top padding
    pub top: u16,
    /// Right padding
    pub right: u16,
    /// Bottom padding
    pub bottom: u16,
    /// Left padding
    pub left: u16,
}

impl Padding {
    /// Padding of zero
    pub const ZERO: Padding = Padding {
        top: 0,
        right: 0,
        bottom: 0,
        left: 0,
    };

    /// Create a Padding that is equal on all sides
    pub const fn new(padding: u16) -> Padding {
        Padding {
            top: padding,
            right: padding,
            bottom: padding,
            left: padding,
        }
    }
}

impl std::convert::From<u16> for Padding {
    fn from(p: u16) -> Self {
        Padding {
            top: p,
            right: p,
            bottom: p,
            left: p,
        }
    }
}

impl std::convert::From<[u16; 2]> for Padding {
    fn from(p: [u16; 2]) -> Self {
        Padding {
            top: p[0],
            right: p[1],
            bottom: p[0],
            left: p[1],
        }
    }
}

impl std::convert::From<[u16; 4]> for Padding {
    fn from(p: [u16; 4]) -> Self {
        Padding {
            top: p[0],
            right: p[1],
            bottom: p[2],
            left: p[3],
        }
    }
}