1use crate::color::Color;
4
5#[derive(Debug, Clone, Copy)]
7pub struct ShadowLayer {
8 pub offset_x: f32,
10 pub offset_y: f32,
12 pub blur: f32,
14 pub spread: f32,
16 pub color: Color,
18}
19
20impl ShadowLayer {
21 pub const NONE: Self = Self {
23 offset_x: 0.0,
24 offset_y: 0.0,
25 blur: 0.0,
26 spread: 0.0,
27 color: Color::TRANSPARENT,
28 };
29}
30
31#[derive(Debug, Clone, Copy)]
33pub struct Shadows {
34 pub none: ShadowLayer,
36 pub sm: ShadowLayer,
38 pub md: ShadowLayer,
40 pub lg: ShadowLayer,
42}
43
44impl Default for Shadows {
45 fn default() -> Self {
46 let shadow_color = Color::BLACK.with_alpha(0.15);
47 Self {
48 none: ShadowLayer::NONE,
49 sm: ShadowLayer {
50 offset_x: 0.0,
51 offset_y: 1.0,
52 blur: 3.0,
53 spread: 0.0,
54 color: shadow_color,
55 },
56 md: ShadowLayer {
57 offset_x: 0.0,
58 offset_y: 2.0,
59 blur: 6.0,
60 spread: 0.0,
61 color: shadow_color,
62 },
63 lg: ShadowLayer {
64 offset_x: 0.0,
65 offset_y: 4.0,
66 blur: 12.0,
67 spread: 0.0,
68 color: shadow_color,
69 },
70 }
71 }
72}
73
74#[cfg(test)]
79mod tests {
80 use super::*;
81
82 #[test]
83 fn shadow_none_is_transparent() {
84 let s = Shadows::default();
85 assert_eq!(s.none.color.a, 0.0);
86 assert_eq!(s.none.blur, 0.0);
87 }
88
89 #[test]
90 fn shadow_blur_is_ascending() {
91 let s = Shadows::default();
92 assert!(s.none.blur < s.sm.blur);
93 assert!(s.sm.blur < s.md.blur);
94 assert!(s.md.blur < s.lg.blur);
95 }
96}