1use crate::{Color, Pixels};
3
4#[derive(Debug, Clone, Copy, PartialEq, Default)]
6pub struct Border {
7 pub color: Color,
9
10 pub width: f32,
12
13 pub radius: Radius,
15}
16
17pub fn rounded(radius: impl Into<Radius>) -> Border {
25 Border::default().rounded(radius)
26}
27
28pub fn color(color: impl Into<Color>) -> Border {
37 Border::default().color(color)
38}
39
40pub fn width(width: impl Into<Pixels>) -> Border {
49 Border::default().width(width)
50}
51
52impl Border {
53 pub fn color(self, color: impl Into<Color>) -> Self {
55 Self {
56 color: color.into(),
57 ..self
58 }
59 }
60
61 pub fn rounded(self, radius: impl Into<Radius>) -> Self {
63 Self {
64 radius: radius.into(),
65 ..self
66 }
67 }
68
69 pub fn width(self, width: impl Into<Pixels>) -> Self {
71 Self {
72 width: width.into().0,
73 ..self
74 }
75 }
76}
77
78#[derive(Debug, Clone, Copy, PartialEq, Default)]
81pub struct Radius {
82 pub top_left: f32,
84 pub top_right: f32,
86 pub bottom_right: f32,
88 pub bottom_left: f32,
90}
91
92pub fn radius(value: impl Into<Pixels>) -> Radius {
94 Radius::new(value)
95}
96
97pub fn top_left(value: impl Into<Pixels>) -> Radius {
99 Radius::default().top_left(value)
100}
101
102pub fn top_right(value: impl Into<Pixels>) -> Radius {
104 Radius::default().top_right(value)
105}
106
107pub fn bottom_right(value: impl Into<Pixels>) -> Radius {
109 Radius::default().bottom_right(value)
110}
111
112pub fn bottom_left(value: impl Into<Pixels>) -> Radius {
114 Radius::default().bottom_left(value)
115}
116
117pub fn top(value: impl Into<Pixels>) -> Radius {
119 Radius::default().top(value)
120}
121
122pub fn bottom(value: impl Into<Pixels>) -> Radius {
124 Radius::default().bottom(value)
125}
126
127pub fn left(value: impl Into<Pixels>) -> Radius {
129 Radius::default().left(value)
130}
131
132pub fn right(value: impl Into<Pixels>) -> Radius {
134 Radius::default().right(value)
135}
136
137impl Radius {
138 pub fn new(value: impl Into<Pixels>) -> Self {
140 let value = value.into().0;
141
142 Self {
143 top_left: value,
144 top_right: value,
145 bottom_right: value,
146 bottom_left: value,
147 }
148 }
149
150 pub fn top_left(self, value: impl Into<Pixels>) -> Self {
152 Self {
153 top_left: value.into().0,
154 ..self
155 }
156 }
157
158 pub fn top_right(self, value: impl Into<Pixels>) -> Self {
160 Self {
161 top_right: value.into().0,
162 ..self
163 }
164 }
165
166 pub fn bottom_right(self, value: impl Into<Pixels>) -> Self {
168 Self {
169 bottom_right: value.into().0,
170 ..self
171 }
172 }
173
174 pub fn bottom_left(self, value: impl Into<Pixels>) -> Self {
176 Self {
177 bottom_left: value.into().0,
178 ..self
179 }
180 }
181
182 pub fn top(self, value: impl Into<Pixels>) -> Self {
184 let value = value.into().0;
185
186 Self {
187 top_left: value,
188 top_right: value,
189 ..self
190 }
191 }
192
193 pub fn bottom(self, value: impl Into<Pixels>) -> Self {
195 let value = value.into().0;
196
197 Self {
198 bottom_left: value,
199 bottom_right: value,
200 ..self
201 }
202 }
203
204 pub fn left(self, value: impl Into<Pixels>) -> Self {
206 let value = value.into().0;
207
208 Self {
209 top_left: value,
210 bottom_left: value,
211 ..self
212 }
213 }
214
215 pub fn right(self, value: impl Into<Pixels>) -> Self {
217 let value = value.into().0;
218
219 Self {
220 top_right: value,
221 bottom_right: value,
222 ..self
223 }
224 }
225}
226
227impl From<f32> for Radius {
228 fn from(radius: f32) -> Self {
229 Self {
230 top_left: radius,
231 top_right: radius,
232 bottom_right: radius,
233 bottom_left: radius,
234 }
235 }
236}
237
238impl From<u8> for Radius {
239 fn from(w: u8) -> Self {
240 Self::from(f32::from(w))
241 }
242}
243
244impl From<u16> for Radius {
245 fn from(w: u16) -> Self {
246 Self::from(f32::from(w))
247 }
248}
249
250impl From<i32> for Radius {
251 fn from(w: i32) -> Self {
252 Self::from(w as f32)
253 }
254}
255
256impl From<Radius> for [f32; 4] {
257 fn from(radi: Radius) -> Self {
258 [
259 radi.top_left,
260 radi.top_right,
261 radi.bottom_right,
262 radi.bottom_left,
263 ]
264 }
265}
266
267impl From<[f32; 4]> for Radius {
268 fn from(value: [f32; 4]) -> Self {
275 Self {
276 top_left: value[0],
277 top_right: value[1],
278 bottom_right: value[2],
279 bottom_left: value[3],
280 }
281 }
282}
283
284impl From<[u8; 4]> for Radius {
285 fn from(value: [u8; 4]) -> Self {
292 Self {
293 top_left: f32::from(value[0]),
294 top_right: f32::from(value[1]),
295 bottom_right: f32::from(value[2]),
296 bottom_left: f32::from(value[3]),
297 }
298 }
299}
300
301impl From<[u16; 4]> for Radius {
302 fn from(value: [u16; 4]) -> Self {
309 Self {
310 top_left: f32::from(value[0]),
311 top_right: f32::from(value[1]),
312 bottom_right: f32::from(value[2]),
313 bottom_left: f32::from(value[3]),
314 }
315 }
316}