sequoia_style/
toast_style.rs1use sequoia_core::Color;
2
3use crate::Backdrop;
4
5#[derive(Clone, Copy, Debug, Default, PartialEq)]
6pub struct ToastStyle {
7 pub background: Option<Color>,
8 pub border: Option<Color>,
9 pub border_width: Option<f32>,
10 pub text: Option<Color>,
11 pub text_secondary: Option<Color>,
12 pub font_size: Option<f32>,
13 pub radius: Option<f32>,
14 pub padding: Option<(f32, f32)>,
15
16 pub info: Option<Color>,
17 pub success: Option<Color>,
18 pub warn: Option<Color>,
19 pub error: Option<Color>,
20
21 pub backdrop: Option<Backdrop>,
22}
23
24impl ToastStyle {
25 pub const fn new() -> Self {
26 Self {
27 background: None,
28 border: None,
29 border_width: None,
30 text: None,
31 text_secondary: None,
32 font_size: None,
33 radius: None,
34 padding: None,
35 info: None,
36 success: None,
37 warn: None,
38 error: None,
39 backdrop: None,
40 }
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 text(mut self, color: Color) -> Self {
59 self.text = Some(color);
60 self
61 }
62
63 pub const fn text_secondary(mut self, color: Color) -> Self {
64 self.text_secondary = Some(color);
65 self
66 }
67
68 pub const fn font_size(mut self, size: f32) -> Self {
69 self.font_size = Some(size);
70 self
71 }
72
73 pub const fn radius(mut self, radius: f32) -> Self {
74 self.radius = Some(radius);
75 self
76 }
77
78 pub const fn padding_xy(mut self, pad_x: f32, pad_y: f32) -> Self {
79 self.padding = Some((pad_x, pad_y));
80 self
81 }
82
83 pub const fn info(mut self, color: Color) -> Self {
84 self.info = Some(color);
85 self
86 }
87
88 pub const fn success(mut self, color: Color) -> Self {
89 self.success = Some(color);
90 self
91 }
92
93 pub const fn warn(mut self, color: Color) -> Self {
94 self.warn = Some(color);
95 self
96 }
97
98 pub const fn error(mut self, color: Color) -> Self {
99 self.error = Some(color);
100 self
101 }
102
103 pub const fn backdrop(mut self, backdrop: Backdrop) -> Self {
104 self.backdrop = Some(backdrop);
105 self
106 }
107}
108
109#[cfg(test)]
110mod tests {
111 use super::*;
112
113 #[test]
114 fn const_composition_keeps_base() {
115 const CUSTOM: ToastStyle = ToastStyle::new().radius(10.0);
116 assert_eq!(CUSTOM.radius, Some(10.0));
117 assert_eq!(CUSTOM.text, None);
118 assert_eq!(CUSTOM.info, None);
119 }
120
121 #[test]
122 fn kind_colors_chain() {
123 const CUSTOM: ToastStyle = ToastStyle::new().info(Color::WHITE).error(Color::BLACK);
124 assert_eq!(CUSTOM.info, Some(Color::WHITE));
125 assert_eq!(CUSTOM.error, Some(Color::BLACK));
126 assert_eq!(CUSTOM.success, None);
127 }
128
129 #[test]
130 fn backdrop_chain() {
131 const CUSTOM: ToastStyle = ToastStyle::new().backdrop(Backdrop::XS);
132 assert_eq!(CUSTOM.backdrop, Some(Backdrop::XS));
133 assert_eq!(CUSTOM.background, None);
134 }
135}