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) -> u32 {
24 match self {
25 ElevationIndex::Background => 0,
26 ElevationIndex::Surface => 100,
27 ElevationIndex::ElevatedSurface => 200,
28 ElevationIndex::Wash => 250,
29 ElevationIndex::ModalSurface => 300,
30 ElevationIndex::DraggedElement => 900,
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(1.)),
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(1.)),
49 blur_radius: px(3.),
50 spread_radius: px(0.),
51 },
52 BoxShadow {
53 color: hsla(0., 0., 0., 0.20),
54 offset: point(px(3.), px(1.)),
55 blur_radius: px(12.),
56 spread_radius: px(0.),
57 },
58 ],
59
60 _ => smallvec![],
61 }
62 }
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66pub enum LayerIndex {
67 BehindElement,
68 Element,
69 ElevatedElement,
70}
71
72impl LayerIndex {
73 pub fn usize(&self) -> usize {
74 match *self {
75 LayerIndex::BehindElement => 0,
76 LayerIndex::Element => 100,
77 LayerIndex::ElevatedElement => 200,
78 }
79 }
80}
81
82#[derive(Debug, Clone, Copy, PartialEq, Eq)]
83pub enum ElementIndex {
84 Effect,
85 Background,
86 Tint,
87 Highlight,
88 Content,
89 Overlay,
90}
91
92impl ElementIndex {
93 pub fn usize(&self) -> usize {
94 match *self {
95 ElementIndex::Effect => 0,
96 ElementIndex::Background => 100,
97 ElementIndex::Tint => 200,
98 ElementIndex::Highlight => 300,
99 ElementIndex::Content => 400,
100 ElementIndex::Overlay => 500,
101 }
102 }
103}