|
1 |
| -use gpui::{Div, ElementFocus, ElementInteractivity, Styled}; |
| 1 | +use gpui::{Div, ElementFocus, ElementInteractivity, Styled, UniformList, ViewContext}; |
| 2 | +use theme2::ActiveTheme; |
2 | 3 |
|
3 |
| -use crate::UITextSize; |
| 4 | +use crate::{ElevationIndex, UITextSize}; |
| 5 | + |
| 6 | +fn elevated<E: Styled, V: 'static>(this: E, cx: &mut ViewContext<V>, index: ElevationIndex) -> E { |
| 7 | + this.bg(cx.theme().colors().elevated_surface_background) |
| 8 | + .rounded_lg() |
| 9 | + .border() |
| 10 | + .border_color(cx.theme().colors().border_variant) |
| 11 | + .shadow(index.shadow()) |
| 12 | +} |
4 | 13 |
|
5 | 14 | /// Extends [`Styled`](gpui::Styled) with Zed specific styling methods.
|
6 | 15 | pub trait StyledExt: Styled {
|
@@ -64,6 +73,48 @@ pub trait StyledExt: Styled {
|
64 | 73 |
|
65 | 74 | self.text_size(size)
|
66 | 75 | }
|
| 76 | + |
| 77 | + /// The [`Surface`](ui2::ElevationIndex::Surface) elevation level, located above the app background, is the standard level for all elements |
| 78 | + /// |
| 79 | + /// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()` |
| 80 | + /// |
| 81 | + /// Example Elements: Title Bar, Panel, Tab Bar, Editor |
| 82 | + fn elevation_1<V: 'static>(self, cx: &mut ViewContext<V>) -> Self |
| 83 | + where |
| 84 | + Self: Styled + Sized, |
| 85 | + { |
| 86 | + elevated(self, cx, ElevationIndex::Surface) |
| 87 | + } |
| 88 | + |
| 89 | + /// Non-Modal Elevated Surfaces appear above the [`Surface`](ui2::ElevationIndex::Surface) layer and is used for things that should appear above most UI elements like an editor or panel, but not elements like popovers, context menus, modals, etc. |
| 90 | + /// |
| 91 | + /// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()` |
| 92 | + /// |
| 93 | + /// Examples: Notifications, Palettes, Detached/Floating Windows, Detached/Floating Panels |
| 94 | + fn elevation_2<V: 'static>(self, cx: &mut ViewContext<V>) -> Self |
| 95 | + where |
| 96 | + Self: Styled + Sized, |
| 97 | + { |
| 98 | + elevated(self, cx, ElevationIndex::ElevatedSurface) |
| 99 | + } |
| 100 | + |
| 101 | + // There is no elevation 3, as the third elevation level is reserved for wash layers. See [`Elevation`](ui2::Elevation). |
| 102 | + |
| 103 | + /// Modal Surfaces are used for elements that should appear above all other UI elements and are located above the wash layer. This is the maximum elevation at which UI elements can be rendered in their default state. |
| 104 | + /// |
| 105 | + /// Elements rendered at this layer should have an enforced behavior: Any interaction outside of the modal will either dismiss the modal or prompt an action (Save your progress, etc) then dismiss the modal. |
| 106 | + /// |
| 107 | + /// If the element does not have this behavior, it should be rendered at the [`Elevated Surface`](ui2::ElevationIndex::ElevatedSurface) layer. |
| 108 | + /// |
| 109 | + /// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()` |
| 110 | + /// |
| 111 | + /// Examples: Settings Modal, Channel Management, Wizards/Setup UI, Dialogs |
| 112 | + fn elevation_4<V: 'static>(self, cx: &mut ViewContext<V>) -> Self |
| 113 | + where |
| 114 | + Self: Styled + Sized, |
| 115 | + { |
| 116 | + elevated(self, cx, ElevationIndex::ModalSurface) |
| 117 | + } |
67 | 118 | }
|
68 | 119 |
|
69 | 120 | impl<V, I, F> StyledExt for Div<V, I, F>
|
|
72 | 123 | F: ElementFocus<V>,
|
73 | 124 | {
|
74 | 125 | }
|
| 126 | + |
| 127 | +impl<V> StyledExt for UniformList<V> {} |
0 commit comments