Skip to main content

sequoia_style/
form_style.rs

1use sequoia_core::Color;
2
3use crate::ButtonStyle;
4
5#[derive(Clone, Copy, Debug, Default, PartialEq)]
6pub struct FormStyle {
7    pub error: Option<Color>,
8
9    pub label_size: Option<f32>,
10
11    pub error_size: Option<f32>,
12
13    pub button: Option<ButtonStyle>,
14}
15
16impl FormStyle {
17    pub const fn new() -> Self {
18        Self {
19            error: None,
20            label_size: None,
21            error_size: None,
22            button: None,
23        }
24    }
25
26    pub const fn error(mut self, color: Color) -> Self {
27        self.error = Some(color);
28        self
29    }
30
31    pub const fn label_size(mut self, size: f32) -> Self {
32        self.label_size = Some(size);
33        self
34    }
35
36    pub const fn error_size(mut self, size: f32) -> Self {
37        self.error_size = Some(size);
38        self
39    }
40
41    pub const fn button(mut self, style: ButtonStyle) -> Self {
42        self.button = Some(style);
43        self
44    }
45}
46
47pub const FORM_ERROR: Color = Color::rgb8(0xFF, 0x5F, 0x57);
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn builders_compose() {
55        let s = FormStyle::new()
56            .label_size(13.0)
57            .error_size(10.0)
58            .button(ButtonStyle::PRIMARY);
59        assert_eq!(s.label_size, Some(13.0));
60        assert_eq!(s.error_size, Some(10.0));
61        assert_eq!(s.error, None);
62        assert_eq!(s.button, Some(ButtonStyle::PRIMARY));
63        assert_eq!(FORM_ERROR, Color::rgb8(0xFF, 0x5F, 0x57));
64    }
65}