1use gpui::{hsla, point, px, BoxShadow};
2use smallvec::{smallvec, SmallVec};
3
4#[doc = include_str!("docs/elevation.md")]
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum Elevation {
7 ElevationIndex(ElevationIndex),
8 LayerIndex(LayerIndex),
9 ElementIndex(ElementIndex),
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum ElevationIndex {
14 Background,
15 Surface,
16 ElevatedSurface,
17 Wash,
18 ModalSurface,
19 DraggedElement,
20}
21
22impl ElevationIndex {
23 pub fn z_index(self) -> u8 {
24 match self {
25 ElevationIndex::Background => 0,
26 ElevationIndex::Surface => 42,
27 ElevationIndex::ElevatedSurface => 84,
28 ElevationIndex::Wash => 126,
29 ElevationIndex::ModalSurface => 168,
30 ElevationIndex::DraggedElement => 210,
31 }
32 }
33
34 pub fn shadow(self) -> SmallVec<[BoxShadow; 2]> {
35 match self {
36 ElevationIndex::Surface => smallvec![],
37
38 ElevationIndex::ElevatedSurface => smallvec![BoxShadow {
39 color: hsla(0., 0., 0., 0.12),
40 offset: point(px(0.), px(2.)),
41 blur_radius: px(3.),
42 spread_radius: px(0.),
43 }],
44
45 ElevationIndex::ModalSurface => smallvec![
46 BoxShadow {
47 color: hsla(0., 0., 0., 0.12),
48 offset: point(px(0.), px(2.)),
49 blur_radius: px(3.),
50 spread_radius: px(0.),
51 },
52 BoxShadow {
53 color: hsla(0., 0., 0., 0.08),
54 offset: point(px(0.), px(3.)),
55 blur_radius: px(6.),
56 spread_radius: px(0.),
57 },
58 BoxShadow {
59 color: hsla(0., 0., 0., 0.04),
60 offset: point(px(0.), px(6.)),
61 blur_radius: px(12.),
62 spread_radius: px(0.),
63 },
64 ],
65
66 _ => smallvec![],
67 }
68 }
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq)]
72pub enum LayerIndex {
73 BehindElement,
74 Element,
75 ElevatedElement,
76}
77
78impl LayerIndex {
79 pub fn usize(&self) -> usize {
80 match *self {
81 LayerIndex::BehindElement => 0,
82 LayerIndex::Element => 100,
83 LayerIndex::ElevatedElement => 200,
84 }
85 }
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq)]
89pub enum ElementIndex {
90 Effect,
91 Background,
92 Tint,
93 Highlight,
94 Content,
95 Overlay,
96}
97
98impl ElementIndex {
99 pub fn usize(&self) -> usize {
100 match *self {
101 ElementIndex::Effect => 0,
102 ElementIndex::Background => 100,
103 ElementIndex::Tint => 200,
104 ElementIndex::Highlight => 300,
105 ElementIndex::Content => 400,
106 ElementIndex::Overlay => 500,
107 }
108 }
109}