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
15/// Trait for components that support a border.
16pub trait Bordered {
17    fn border(&self) -> Option<&Border>;
18}
19
20/// Mutable access to border — needed by builder traits.
21pub trait BorderedMut: Bordered {
22    fn set_border(&mut self, border: Option<Border>);
23}
24
25/// Builder API for border.
26pub trait BorderedExt: BorderedMut + Sized {
27    fn border_color(mut self, color: impl Into<String>, width: f32) -> Self {
28        self.set_border(Some(Border {
29            color: color.into(),
30            width,
31        }));
32        self
33    }
34
35    fn border_none(mut self) -> Self {
36        self.set_border(None);
37        self
38    }
39}
40
41impl<T: BorderedMut + Sized> BorderedExt for T {}