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