elevation.rs

 1use gpui::{hsla, point, px, BoxShadow};
 2use smallvec::{smallvec, SmallVec};
 3
 4#[doc = include_str!("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    AppBackground,
15    UISurface,
16    ElevatedSurface,
17    Wash,
18    ModalSurfaces,
19    DraggedElement,
20}
21
22impl ElevationIndex {
23    pub fn z_index(self) -> u32 {
24        match self {
25            ElevationIndex::AppBackground => 0,
26            ElevationIndex::UISurface => 100,
27            ElevationIndex::ElevatedSurface => 200,
28            ElevationIndex::Wash => 300,
29            ElevationIndex::ModalSurfaces => 400,
30            ElevationIndex::DraggedElement => 900,
31        }
32    }
33
34    pub fn shadow(self) -> SmallVec<[BoxShadow; 2]> {
35        match self {
36            ElevationIndex::AppBackground => smallvec![],
37
38            ElevationIndex::UISurface => 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            _ => smallvec![BoxShadow {
46                color: hsla(0., 0., 0., 0.32),
47                offset: point(px(1.), px(3.)),
48                blur_radius: px(12.),
49                spread_radius: px(0.),
50            }],
51        }
52    }
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum LayerIndex {
57    BehindElement,
58    Element,
59    ElevatedElement,
60}
61
62impl LayerIndex {
63    pub fn usize(&self) -> usize {
64        match *self {
65            LayerIndex::BehindElement => 0,
66            LayerIndex::Element => 100,
67            LayerIndex::ElevatedElement => 200,
68        }
69    }
70}
71
72#[derive(Debug, Clone, Copy, PartialEq, Eq)]
73pub enum ElementIndex {
74    Effect,
75    Background,
76    Tint,
77    Highlight,
78    Content,
79    Overlay,
80}
81
82impl ElementIndex {
83    pub fn usize(&self) -> usize {
84        match *self {
85            ElementIndex::Effect => 0,
86            ElementIndex::Background => 100,
87            ElementIndex::Tint => 200,
88            ElementIndex::Highlight => 300,
89            ElementIndex::Content => 400,
90            ElementIndex::Overlay => 500,
91        }
92    }
93}