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