elevation.rs

 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
12impl Into<Elevation> for ElevationIndex {
13    fn into(self) -> Elevation {
14        Elevation::ElevationIndex(self)
15    }
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum ElevationIndex {
20    Background,
21    Surface,
22    ElevatedSurface,
23    Wash,
24    ModalSurface,
25    DraggedElement,
26}
27
28impl ElevationIndex {
29    pub fn shadow(self) -> SmallVec<[BoxShadow; 2]> {
30        match self {
31            ElevationIndex::Surface => smallvec![],
32
33            ElevationIndex::ElevatedSurface => smallvec![BoxShadow {
34                color: hsla(0., 0., 0., 0.12),
35                offset: point(px(0.), px(2.)),
36                blur_radius: px(3.),
37                spread_radius: px(0.),
38            }],
39
40            ElevationIndex::ModalSurface => smallvec![
41                BoxShadow {
42                    color: hsla(0., 0., 0., 0.12),
43                    offset: point(px(0.), px(2.)),
44                    blur_radius: px(3.),
45                    spread_radius: px(0.),
46                },
47                BoxShadow {
48                    color: hsla(0., 0., 0., 0.08),
49                    offset: point(px(0.), px(3.)),
50                    blur_radius: px(6.),
51                    spread_radius: px(0.),
52                },
53                BoxShadow {
54                    color: hsla(0., 0., 0., 0.04),
55                    offset: point(px(0.), px(6.)),
56                    blur_radius: px(12.),
57                    spread_radius: px(0.),
58                },
59            ],
60
61            _ => smallvec![],
62        }
63    }
64}
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq)]
67pub enum LayerIndex {
68    BehindElement,
69    Element,
70    ElevatedElement,
71}
72
73/// An appropriate z-index for the given layer based on its intended usage.
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
75pub enum ElementIndex {
76    Effect,
77    Background,
78    Tint,
79    Highlight,
80    Content,
81    Overlay,
82}