Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T06:32:46.666Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

elevation.rs

118 lines · 5.0 KB · rust
1use std::fmt::{self, Display, Formatter};
2
3use gpui::{App, BoxShadow, Hsla, hsla, px};
4use theme::{ActiveTheme, Appearance};
5
6/// Today, elevation is primarily used to add shadows to elements, and set the correct background for elements like buttons.
7///
8/// Elevation can be thought of as the physical closeness of an element to the
9/// user. Elements with lower elevations are physically further away on the
10/// z-axis and appear to be underneath elements with higher elevations.
11///
12/// In the future, a more complete approach to elevation may be added.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum ElevationIndex {
15    /// On the layer of the app background. This is under panels, panes, and
16    /// other surfaces.
17    Background,
18    /// The primary surface – Contains panels, panes, containers, etc.
19    Surface,
20    /// The same elevation as the primary surface, but used for the editable areas, like buffers
21    EditorSurface,
22    /// A surface that is elevated above the primary surface. but below washes, models, and dragged elements.
23    ElevatedSurface,
24    /// A surface above the [ElevationIndex::ElevatedSurface] that is used for dialogs, alerts, modals, etc.
25    ModalSurface,
26}
27
28impl Display for ElevationIndex {
29    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
30        match self {
31            ElevationIndex::Background => write!(f, "Background"),
32            ElevationIndex::Surface => write!(f, "Surface"),
33            ElevationIndex::EditorSurface => write!(f, "Editor Surface"),
34            ElevationIndex::ElevatedSurface => write!(f, "Elevated Surface"),
35            ElevationIndex::ModalSurface => write!(f, "Modal Surface"),
36        }
37    }
38}
39
40impl ElevationIndex {
41    /// Returns an appropriate shadow for the given elevation index.
42    pub fn shadow(self, cx: &App) -> Vec<BoxShadow> {
43        let is_light = cx.theme().appearance() == Appearance::Light;
44
45        match self {
46            ElevationIndex::Surface => vec![],
47            ElevationIndex::EditorSurface => vec![],
48
49            ElevationIndex::ElevatedSurface => vec![
50                BoxShadow::new(px(0.), px(2.), hsla(0., 0., 0., 0.12)).blur_radius(px(3.)),
51                BoxShadow::new(
52                    px(0.),
53                    px(1.),
54                    hsla(0., 0., 0., if is_light { 0.03 } else { 0.06 }),
55                ),
56            ],
57
58            ElevationIndex::ModalSurface => vec![
59                BoxShadow::new(
60                    px(0.),
61                    px(2.),
62                    hsla(0., 0., 0., if is_light { 0.06 } else { 0.12 }),
63                )
64                .blur_radius(px(3.)),
65                BoxShadow::new(
66                    px(0.),
67                    px(3.),
68                    hsla(0., 0., 0., if is_light { 0.06 } else { 0.08 }),
69                )
70                .blur_radius(px(6.)),
71                BoxShadow::new(px(0.), px(6.), hsla(0., 0., 0., 0.04)).blur_radius(px(12.)),
72                BoxShadow::new(
73                    px(0.),
74                    px(1.),
75                    hsla(0., 0., 0., if is_light { 0.04 } else { 0.12 }),
76                ),
77            ],
78
79            _ => vec![],
80        }
81    }
82
83    /// Returns the background color for the given elevation index.
84    pub fn bg(&self, cx: &mut App) -> Hsla {
85        match self {
86            ElevationIndex::Background => cx.theme().colors().background,
87            ElevationIndex::Surface => cx.theme().colors().surface_background,
88            ElevationIndex::EditorSurface => cx.theme().colors().editor_background,
89            ElevationIndex::ElevatedSurface => cx.theme().colors().elevated_surface_background,
90            ElevationIndex::ModalSurface => cx.theme().colors().elevated_surface_background,
91        }
92    }
93
94    /// Returns a color that is appropriate a filled element on this elevation
95    pub fn on_elevation_bg(&self, cx: &App) -> Hsla {
96        match self {
97            ElevationIndex::Background => cx.theme().colors().surface_background,
98            ElevationIndex::Surface => cx.theme().colors().background,
99            ElevationIndex::EditorSurface => cx.theme().colors().surface_background,
100            ElevationIndex::ElevatedSurface => cx.theme().colors().background,
101            ElevationIndex::ModalSurface => cx.theme().colors().background,
102        }
103    }
104
105    /// Attempts to return a darker background color than the current elevation index's background.
106    ///
107    /// If the current background color is already dark, it will return a lighter color instead.
108    pub fn darker_bg(&self, cx: &App) -> Hsla {
109        match self {
110            ElevationIndex::Background => cx.theme().colors().surface_background,
111            ElevationIndex::Surface => cx.theme().colors().editor_background,
112            ElevationIndex::EditorSurface => cx.theme().colors().surface_background,
113            ElevationIndex::ElevatedSurface => cx.theme().colors().editor_background,
114            ElevationIndex::ModalSurface => cx.theme().colors().editor_background,
115        }
116    }
117}
118
Served at tenant.openagents/omega Member data and write actions are omitted.