clay_layout/layout/
padding.rs

1use crate::bindings::*;
2
3/// Represents padding with values for left, right, top, and bottom.
4#[derive(Debug, Copy, Clone, Default)]
5pub struct Padding {
6    /// Padding value for the left side.
7    pub left: u16,
8    /// Padding value for the right side.
9    pub right: u16,
10    /// Padding value for the top side.
11    pub top: u16,
12    /// Padding value for the bottom side.
13    pub bottom: u16,
14}
15
16impl Padding {
17    /// Creates a new `Padding` instance with specific values for all sides.
18    pub fn new_rect(left: u16, right: u16, top: u16, bottom: u16) -> Self {
19        Self {
20            left,
21            right,
22            top,
23            bottom,
24        }
25    }
26
27    /// Creates a new `Padding` instance with the same value for all sides.
28    pub fn all(value: u16) -> Self {
29        Self::new_rect(value, value, value, value)
30    }
31
32    /// Creates a new `Padding` instance with the same value for left and right sides.
33    pub fn horizontal(value: u16) -> Self {
34        Self::new_rect(value, value, 0, 0)
35    }
36
37    /// Creates a new `Padding` instance with the same value for top and bottom sides.
38    pub fn vertical(value: u16) -> Self {
39        Self::new_rect(0, 0, value, value)
40    }
41
42    /// Creates a new `Padding` instance with default values (all zero).
43    pub fn new() -> Self {
44        Self::default()
45    }
46
47    /// Sets the padding value for the left side.
48    pub fn left(&mut self, value: u16) -> &mut Self {
49        self.left = value;
50        self
51    }
52
53    /// Sets the padding value for the right side.
54    pub fn right(&mut self, value: u16) -> &mut Self {
55        self.right = value;
56        self
57    }
58
59    /// Sets the padding value for the top side.
60    pub fn top(&mut self, value: u16) -> &mut Self {
61        self.top = value;
62        self
63    }
64
65    /// Sets the padding value for the bottom side.
66    pub fn bottom(&mut self, value: u16) -> &mut Self {
67        self.bottom = value;
68        self
69    }
70
71    /// Finalizes the modifications and returns the updated `Padding` instance.
72    pub fn end(&mut self) -> Self {
73        *self
74    }
75}
76
77impl From<Clay_Padding> for Padding {
78    fn from(value: Clay_Padding) -> Self {
79        Self {
80            left: value.left,
81            right: value.right,
82            top: value.top,
83            bottom: value.bottom,
84        }
85    }
86}
87impl From<Padding> for Clay_Padding {
88    fn from(value: Padding) -> Self {
89        Self {
90            left: value.left,
91            right: value.right,
92            top: value.top,
93            bottom: value.bottom,
94        }
95    }
96}
97
98impl From<(u16, u16, u16, u16)> for Padding {
99    fn from(other: (u16, u16, u16, u16)) -> Self {
100        Self::new_rect(other.0, other.1, other.2, other.3)
101    }
102}