sequoia_style/
switch_style.rs1use sequoia_core::Color;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq)]
4pub struct SwitchStyle {
5 pub track_on: Option<Color>,
6 pub track_off: Option<Color>,
7 pub track_disabled: Option<Color>,
8 pub thumb: Option<Color>,
9 pub thumb_on: Option<Color>,
10 pub thumb_disabled: Option<Color>,
11 pub border: Option<Color>,
12 pub border_on: Option<Color>,
13 pub text: Option<Color>,
14 pub font_size: Option<f32>,
15 pub width: Option<f32>,
16 pub height: Option<f32>,
17 pub thumb_size: Option<f32>,
18}
19
20impl SwitchStyle {
21 pub const fn new() -> Self {
22 Self {
23 track_on: None,
24 track_off: None,
25 track_disabled: None,
26 thumb: None,
27 thumb_on: None,
28 thumb_disabled: None,
29 border: None,
30 border_on: None,
31 text: None,
32 font_size: None,
33 width: None,
34 height: None,
35 thumb_size: None,
36 }
37 }
38
39 pub const fn track_on(mut self, color: Color) -> Self {
40 self.track_on = Some(color);
41 self
42 }
43
44 pub const fn track_off(mut self, color: Color) -> Self {
45 self.track_off = Some(color);
46 self
47 }
48
49 pub const fn track_disabled(mut self, color: Color) -> Self {
50 self.track_disabled = Some(color);
51 self
52 }
53
54 pub const fn thumb(mut self, color: Color) -> Self {
55 self.thumb = Some(color);
56 self
57 }
58
59 pub const fn thumb_on(mut self, color: Color) -> Self {
60 self.thumb_on = Some(color);
61 self
62 }
63
64 pub const fn thumb_disabled(mut self, color: Color) -> Self {
65 self.thumb_disabled = Some(color);
66 self
67 }
68
69 pub const fn border(mut self, color: Color) -> Self {
70 self.border = Some(color);
71 self
72 }
73
74 pub const fn border_on(mut self, color: Color) -> Self {
75 self.border_on = Some(color);
76 self
77 }
78
79 pub const fn text(mut self, color: Color) -> Self {
80 self.text = Some(color);
81 self
82 }
83
84 pub const fn font_size(mut self, size: f32) -> Self {
85 self.font_size = Some(size);
86 self
87 }
88
89 pub const fn width(mut self, width: f32) -> Self {
90 self.width = Some(width);
91 self
92 }
93
94 pub const fn height(mut self, height: f32) -> Self {
95 self.height = Some(height);
96 self
97 }
98
99 pub const fn thumb_size(mut self, size: f32) -> Self {
100 self.thumb_size = Some(size);
101 self
102 }
103}
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108
109 #[test]
110 fn const_composition_keeps_base() {
111 const CUSTOM: SwitchStyle = SwitchStyle::new().track_on(Color::WHITE);
112 assert_eq!(CUSTOM.track_on, Some(Color::WHITE));
113 assert_eq!(CUSTOM.track_off, None);
114 }
115
116 #[test]
117 fn struct_update_syntax_keeps_base() {
118 const CUSTOM: SwitchStyle = SwitchStyle {
119 track_on: Some(Color::WHITE),
120 ..SwitchStyle::new()
121 };
122 assert_eq!(CUSTOM.track_on, Some(Color::WHITE));
123 assert_eq!(CUSTOM.thumb, None);
124 }
125}