1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use gpui::{hsla, point, px, BoxShadow};
use smallvec::{smallvec, SmallVec};

#[doc = include_str!("docs/elevation.md")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Elevation {
    ElevationIndex(ElevationIndex),
    LayerIndex(LayerIndex),
    ElementIndex(ElementIndex),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ElevationIndex {
    Background,
    Surface,
    ElevatedSurface,
    Wash,
    ModalSurface,
    DraggedElement,
}

impl ElevationIndex {
    pub fn z_index(self) -> u32 {
        match self {
            ElevationIndex::Background => 0,
            ElevationIndex::Surface => 100,
            ElevationIndex::ElevatedSurface => 200,
            ElevationIndex::Wash => 250,
            ElevationIndex::ModalSurface => 300,
            ElevationIndex::DraggedElement => 900,
        }
    }

    pub fn shadow(self) -> SmallVec<[BoxShadow; 2]> {
        match self {
            ElevationIndex::Surface => smallvec![],

            ElevationIndex::ElevatedSurface => smallvec![BoxShadow {
                color: hsla(0., 0., 0., 0.12),
                offset: point(px(0.), px(1.)),
                blur_radius: px(3.),
                spread_radius: px(0.),
            }],

            ElevationIndex::ModalSurface => smallvec![
                BoxShadow {
                    color: hsla(0., 0., 0., 0.12),
                    offset: point(px(0.), px(1.)),
                    blur_radius: px(3.),
                    spread_radius: px(0.),
                },
                BoxShadow {
                    color: hsla(0., 0., 0., 0.20),
                    offset: point(px(3.), px(1.)),
                    blur_radius: px(12.),
                    spread_radius: px(0.),
                },
            ],

            _ => smallvec![],
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LayerIndex {
    BehindElement,
    Element,
    ElevatedElement,
}

impl LayerIndex {
    pub fn usize(&self) -> usize {
        match *self {
            LayerIndex::BehindElement => 0,
            LayerIndex::Element => 100,
            LayerIndex::ElevatedElement => 200,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ElementIndex {
    Effect,
    Background,
    Tint,
    Highlight,
    Content,
    Overlay,
}

impl ElementIndex {
    pub fn usize(&self) -> usize {
        match *self {
            ElementIndex::Effect => 0,
            ElementIndex::Background => 100,
            ElementIndex::Tint => 200,
            ElementIndex::Highlight => 300,
            ElementIndex::Content => 400,
            ElementIndex::Overlay => 500,
        }
    }
}