sequoia_style/
modal_style.rs1use sequoia_core::Color;
2
3use crate::Backdrop;
4
5#[derive(Clone, Copy, Debug, Default, PartialEq)]
6pub struct ModalStyle {
7 pub background: Option<Color>,
8 pub border: Option<Color>,
9 pub border_width: Option<f32>,
10 pub radius: Option<f32>,
11
12 pub scrim: Option<Color>,
13
14 pub backdrop: Option<Backdrop>,
15}
16
17impl ModalStyle {
18 pub const fn new() -> Self {
19 Self {
20 background: None,
21 border: None,
22 border_width: None,
23 radius: None,
24 scrim: None,
25 backdrop: None,
26 }
27 }
28
29 pub const fn background(mut self, color: Color) -> Self {
30 self.background = Some(color);
31 self
32 }
33
34 pub const fn border(mut self, color: Color) -> Self {
35 self.border = Some(color);
36 self
37 }
38
39 pub const fn border_width(mut self, width: f32) -> Self {
40 self.border_width = Some(width);
41 self
42 }
43
44 pub const fn radius(mut self, radius: f32) -> Self {
45 self.radius = Some(radius);
46 self
47 }
48
49 pub const fn scrim(mut self, color: Color) -> Self {
50 self.scrim = Some(color);
51 self
52 }
53
54 pub const fn backdrop(mut self, backdrop: Backdrop) -> Self {
55 self.backdrop = Some(backdrop);
56 self
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn const_composition_keeps_base() {
66 const CUSTOM: ModalStyle = ModalStyle::new().radius(12.0);
67 assert_eq!(CUSTOM.radius, Some(12.0));
68 assert_eq!(CUSTOM.background, None);
69 assert_eq!(CUSTOM.scrim, None);
70 }
71
72 #[test]
73 fn scrim_and_backdrop_chain() {
74 const CUSTOM: ModalStyle = ModalStyle::new().scrim(Color::BLACK).backdrop(Backdrop::MD);
75 assert_eq!(CUSTOM.scrim, Some(Color::BLACK));
76 assert_eq!(CUSTOM.backdrop, Some(Backdrop::MD));
77 }
78}