Skip to main content

sequoia_style/
radio_style.rs

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