Skip to main content

sequoia_style/
chip_style.rs

1use sequoia_core::Color;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq)]
4pub struct ChipStyle {
5    pub background: Option<Color>,
6    pub border: Option<Color>,
7    pub text: Option<Color>,
8    pub selected_background: Option<Color>,
9    pub selected_border: Option<Color>,
10    pub selected_text: Option<Color>,
11    pub font_size: Option<f32>,
12    pub radius: Option<f32>,
13    pub padding: Option<(f32, f32)>,
14}
15
16impl ChipStyle {
17    pub const fn new() -> Self {
18        Self {
19            background: None,
20            border: None,
21            text: None,
22            selected_background: None,
23            selected_border: None,
24            selected_text: None,
25            font_size: None,
26            radius: None,
27            padding: None,
28        }
29    }
30
31    pub const fn background(mut self, color: Color) -> Self {
32        self.background = Some(color);
33        self
34    }
35
36    pub const fn border(mut self, color: Color) -> Self {
37        self.border = Some(color);
38        self
39    }
40
41    pub const fn text(mut self, color: Color) -> Self {
42        self.text = Some(color);
43        self
44    }
45
46    pub const fn selected_background(mut self, color: Color) -> Self {
47        self.selected_background = Some(color);
48        self
49    }
50
51    pub const fn selected_border(mut self, color: Color) -> Self {
52        self.selected_border = Some(color);
53        self
54    }
55
56    pub const fn selected_text(mut self, color: Color) -> Self {
57        self.selected_text = Some(color);
58        self
59    }
60
61    pub const fn font_size(mut self, size: f32) -> Self {
62        self.font_size = Some(size);
63        self
64    }
65
66    pub const fn radius(mut self, radius: f32) -> Self {
67        self.radius = Some(radius);
68        self
69    }
70
71    pub const fn padding_xy(mut self, pad_x: f32, pad_y: f32) -> Self {
72        self.padding = Some((pad_x, pad_y));
73        self
74    }
75}
76
77#[cfg(test)]
78mod tests {
79    use super::*;
80
81    #[test]
82    fn const_composition_keeps_base() {
83        const CUSTOM: ChipStyle = ChipStyle::new().radius(999.0);
84        assert_eq!(CUSTOM.radius, Some(999.0));
85        assert_eq!(CUSTOM.selected_text, None);
86    }
87}