Skip to main content

sequoia_style/
text_field_style.rs

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