clay_layout/layout/
padding.rs1use crate::bindings::*;
2
3#[derive(Debug, Copy, Clone, Default)]
5pub struct Padding {
6 pub left: u16,
8 pub right: u16,
10 pub top: u16,
12 pub bottom: u16,
14}
15
16impl Padding {
17 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 pub fn all(value: u16) -> Self {
29 Self::new_rect(value, value, value, value)
30 }
31
32 pub fn horizontal(value: u16) -> Self {
34 Self::new_rect(value, value, 0, 0)
35 }
36
37 pub fn vertical(value: u16) -> Self {
39 Self::new_rect(0, 0, value, value)
40 }
41
42 pub fn new() -> Self {
44 Self::default()
45 }
46
47 pub fn left(&mut self, value: u16) -> &mut Self {
49 self.left = value;
50 self
51 }
52
53 pub fn right(&mut self, value: u16) -> &mut Self {
55 self.right = value;
56 self
57 }
58
59 pub fn top(&mut self, value: u16) -> &mut Self {
61 self.top = value;
62 self
63 }
64
65 pub fn bottom(&mut self, value: u16) -> &mut Self {
67 self.bottom = value;
68 self
69 }
70
71 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}