Skip to main content

rustmotion_core/traits/
bordered.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
5pub struct Border {
6    pub color: String,
7    #[serde(default = "default_border_width")]
8    pub width: f32,
9}
10
11fn default_border_width() -> f32 {
12    1.0
13}
14
15pub trait Bordered {
16    fn border(&self) -> Option<&Border>;
17}
18
19pub trait BorderedMut: Bordered {
20    fn set_border(&mut self, border: Option<Border>);
21}
22
23pub trait BorderedExt: BorderedMut + Sized {
24    fn border_color(mut self, color: impl Into<String>, width: f32) -> Self {
25        self.set_border(Some(Border {
26            color: color.into(),
27            width,
28        }));
29        self
30    }
31
32    fn border_none(mut self) -> Self {
33        self.set_border(None);
34        self
35    }
36}
37
38impl<T: BorderedMut + Sized> BorderedExt for T {}