1use std::fmt;
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9 #[doc(alias = "GtkBorder")]
13 pub struct Border(BoxedInline<ffi::GtkBorder>);
14
15 match fn {
16 copy => |ptr| ffi::gtk_border_copy(mut_override(ptr)),
17 free => |ptr| ffi::gtk_border_free(ptr),
18 type_ => || ffi::gtk_border_get_type(),
19 }
20}
21
22impl Border {
23 #[doc(alias = "gtk_border_new")]
30 pub fn new() -> Self {
31 assert_initialized_main_thread!();
32 unsafe { Self::uninitialized() }
33 }
34
35 pub fn builder() -> BorderBuilder {
41 BorderBuilder::default()
42 }
43
44 #[inline]
45 pub fn left(&self) -> i16 {
46 self.inner.left
47 }
48
49 #[inline]
50 pub fn set_left(&mut self, left: i16) {
51 self.inner.left = left;
52 }
53
54 #[inline]
55 pub fn right(&self) -> i16 {
56 self.inner.right
57 }
58
59 #[inline]
60 pub fn set_right(&mut self, right: i16) {
61 self.inner.right = right;
62 }
63
64 #[inline]
65 pub fn top(&self) -> i16 {
66 self.inner.top
67 }
68
69 #[inline]
70 pub fn set_top(&mut self, top: i16) {
71 self.inner.top = top;
72 }
73
74 #[inline]
75 pub fn bottom(&self) -> i16 {
76 self.inner.bottom
77 }
78
79 #[inline]
80 pub fn set_bottom(&mut self, bottom: i16) {
81 self.inner.bottom = bottom;
82 }
83}
84
85impl Default for Border {
86 fn default() -> Self {
87 Self::new()
88 }
89}
90
91impl fmt::Debug for Border {
92 fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
93 fmt.debug_struct("Border")
94 .field("left", &self.left())
95 .field("right", &self.right())
96 .field("top", &self.top())
97 .field("bottom", &self.bottom())
98 .finish()
99 }
100}
101
102impl PartialEq for Border {
103 #[inline]
104 fn eq(&self, other: &Self) -> bool {
105 self.left() == other.left()
106 && self.right() == other.right()
107 && self.top() == other.top()
108 && self.bottom() == other.bottom()
109 }
110}
111
112impl Eq for Border {}
113
114#[derive(Clone, Default)]
115#[must_use = "The builder must be built to be used"]
120pub struct BorderBuilder {
121 left: Option<i16>,
122 right: Option<i16>,
123 bottom: Option<i16>,
124 top: Option<i16>,
125}
126
127impl BorderBuilder {
128 pub fn new() -> Self {
131 Self::default()
132 }
133
134 pub fn left(mut self, left: i16) -> Self {
135 self.left = Some(left);
136 self
137 }
138
139 pub fn right(mut self, right: i16) -> Self {
140 self.right = Some(right);
141 self
142 }
143
144 pub fn bottom(mut self, bottom: i16) -> Self {
145 self.bottom = Some(bottom);
146 self
147 }
148
149 pub fn top(mut self, top: i16) -> Self {
150 self.top = Some(top);
151 self
152 }
153
154 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
157 pub fn build(self) -> Border {
158 let mut border = Border::default();
159 if let Some(left) = self.left {
160 border.set_left(left);
161 }
162 if let Some(right) = self.right {
163 border.set_right(right);
164 }
165 if let Some(bottom) = self.bottom {
166 border.set_bottom(bottom);
167 }
168 if let Some(top) = self.top {
169 border.set_top(top);
170 }
171 border
172 }
173}