Skip to main content

sequoia_style/
dialog_style.rs

1use sequoia_core::Color;
2
3use crate::Backdrop;
4
5#[derive(Clone, Copy, Debug, Default, PartialEq)]
6pub struct DialogStyle {
7    pub background: Option<Color>,
8    pub border: Option<Color>,
9    pub border_width: Option<f32>,
10    pub radius: Option<f32>,
11    pub backdrop: Option<Backdrop>,
12
13    pub title_size: Option<f32>,
14
15    pub danger: Option<Color>,
16}
17
18impl DialogStyle {
19    pub const fn new() -> Self {
20        Self {
21            background: None,
22            border: None,
23            border_width: None,
24            radius: None,
25            backdrop: None,
26            title_size: None,
27            danger: 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 border(mut self, color: Color) -> Self {
37        self.border = Some(color);
38        self
39    }
40
41    pub const fn border_width(mut self, width: f32) -> Self {
42        self.border_width = Some(width);
43        self
44    }
45
46    pub const fn radius(mut self, radius: f32) -> Self {
47        self.radius = Some(radius);
48        self
49    }
50
51    pub const fn backdrop(mut self, backdrop: Backdrop) -> Self {
52        self.backdrop = Some(backdrop);
53        self
54    }
55
56    pub const fn title_size(mut self, size: f32) -> Self {
57        self.title_size = Some(size);
58        self
59    }
60
61    pub const fn danger(mut self, color: Color) -> Self {
62        self.danger = Some(color);
63        self
64    }
65}
66
67pub const DIALOG_DANGER: Color = Color::rgb8(0xFF, 0x5F, 0x57);
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn defaults_are_empty_and_danger_const_is_red() {
75        let s = DialogStyle::new().title_size(20.0);
76        assert_eq!(s.title_size, Some(20.0));
77        assert_eq!(s.danger, None);
78        assert_eq!(DIALOG_DANGER, Color::rgb8(0xFF, 0x5F, 0x57));
79    }
80}