Skip to main content

sequoia_style/
form_style.rs

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