Skip to main content

sequoia_style/
text_area_style.rs

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