Editing JSON styles is not very helpful for bringing style changes back to the actual code. This PR adds a buffer that pretends to be Rust, applying any style attribute identifiers it finds. Also supports completions with display of documentation. The effect of the currently selected completion is previewed. Warning diagnostics appear on any unrecognized identifier. https://github.com/user-attachments/assets/af39ff0a-26a5-4835-a052-d8f642b2080c Adds a `#[derive_inspector_reflection]` macro which allows these methods to be enumerated and called by their name. The macro code changes were 95% generated by Zed Agent + Opus 4. Release Notes: * Added an element inspector for development. On debug builds, `dev::ToggleInspector` will open a pane allowing inspecting of element info and modifying styles.
131 lines
4.9 KiB
Rust
131 lines
4.9 KiB
Rust
use gpui::{App, Styled, hsla};
|
|
|
|
use crate::ElevationIndex;
|
|
use crate::prelude::*;
|
|
|
|
fn elevated<E: Styled>(this: E, cx: &App, index: ElevationIndex) -> E {
|
|
this.bg(cx.theme().colors().elevated_surface_background)
|
|
.rounded_lg()
|
|
.border_1()
|
|
.border_color(cx.theme().colors().border_variant)
|
|
.shadow(index.shadow(cx))
|
|
}
|
|
|
|
fn elevated_borderless<E: Styled>(this: E, cx: &mut App, index: ElevationIndex) -> E {
|
|
this.bg(cx.theme().colors().elevated_surface_background)
|
|
.rounded_lg()
|
|
.shadow(index.shadow(cx))
|
|
}
|
|
|
|
/// Extends [`gpui::Styled`] with Zed-specific styling methods.
|
|
#[cfg_attr(debug_assertions, gpui_macros::derive_inspector_reflection)]
|
|
pub trait StyledExt: Styled + Sized {
|
|
/// Horizontally stacks elements.
|
|
///
|
|
/// Sets `flex()`, `flex_row()`, `items_center()`
|
|
fn h_flex(self) -> Self {
|
|
self.flex().flex_row().items_center()
|
|
}
|
|
|
|
/// Vertically stacks elements.
|
|
///
|
|
/// Sets `flex()`, `flex_col()`
|
|
fn v_flex(self) -> Self {
|
|
self.flex().flex_col()
|
|
}
|
|
|
|
/// The [`Surface`](ElevationIndex::Surface) elevation level, located above the app background, is the standard level for all elements
|
|
///
|
|
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
|
|
///
|
|
/// Example Elements: Title Bar, Panel, Tab Bar, Editor
|
|
fn elevation_1(self, cx: &mut App) -> Self {
|
|
elevated(self, cx, ElevationIndex::Surface)
|
|
}
|
|
|
|
/// See [`elevation_1`](Self::elevation_1).
|
|
///
|
|
/// Renders a borderless version [`elevation_1`](Self::elevation_1).
|
|
fn elevation_1_borderless(self, cx: &mut App) -> Self {
|
|
elevated_borderless(self, cx, ElevationIndex::Surface)
|
|
}
|
|
|
|
/// Non-Modal Elevated Surfaces appear above the [`Surface`](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.
|
|
///
|
|
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
|
|
///
|
|
/// Examples: Notifications, Palettes, Detached/Floating Windows, Detached/Floating Panels
|
|
fn elevation_2(self, cx: &App) -> Self {
|
|
elevated(self, cx, ElevationIndex::ElevatedSurface)
|
|
}
|
|
|
|
/// See [`elevation_2`](Self::elevation_2).
|
|
///
|
|
/// Renders a borderless version [`elevation_2`](Self::elevation_2).
|
|
fn elevation_2_borderless(self, cx: &mut App) -> Self {
|
|
elevated_borderless(self, cx, ElevationIndex::ElevatedSurface)
|
|
}
|
|
|
|
/// 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.
|
|
///
|
|
/// 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.
|
|
///
|
|
/// If the element does not have this behavior, it should be rendered at the [`Elevated Surface`](ElevationIndex::ElevatedSurface) layer.
|
|
///
|
|
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
|
|
///
|
|
/// Examples: Settings Modal, Channel Management, Wizards/Setup UI, Dialogs
|
|
fn elevation_3(self, cx: &App) -> Self {
|
|
elevated(self, cx, ElevationIndex::ModalSurface)
|
|
}
|
|
|
|
/// See [`elevation_3`](Self::elevation_3).
|
|
///
|
|
/// Renders a borderless version [`elevation_3`](Self::elevation_3).
|
|
fn elevation_3_borderless(self, cx: &mut App) -> Self {
|
|
elevated_borderless(self, cx, ElevationIndex::ModalSurface)
|
|
}
|
|
|
|
/// The theme's primary border color.
|
|
fn border_primary(self, cx: &mut App) -> Self {
|
|
self.border_color(cx.theme().colors().border)
|
|
}
|
|
|
|
/// The theme's secondary or muted border color.
|
|
fn border_muted(self, cx: &mut App) -> Self {
|
|
self.border_color(cx.theme().colors().border_variant)
|
|
}
|
|
|
|
/// Sets the background color to red for debugging when building UI.
|
|
fn debug_bg_red(self) -> Self {
|
|
self.bg(hsla(0. / 360., 1., 0.5, 1.))
|
|
}
|
|
|
|
/// Sets the background color to green for debugging when building UI.
|
|
fn debug_bg_green(self) -> Self {
|
|
self.bg(hsla(120. / 360., 1., 0.5, 1.))
|
|
}
|
|
|
|
/// Sets the background color to blue for debugging when building UI.
|
|
fn debug_bg_blue(self) -> Self {
|
|
self.bg(hsla(240. / 360., 1., 0.5, 1.))
|
|
}
|
|
|
|
/// Sets the background color to yellow for debugging when building UI.
|
|
fn debug_bg_yellow(self) -> Self {
|
|
self.bg(hsla(60. / 360., 1., 0.5, 1.))
|
|
}
|
|
|
|
/// Sets the background color to cyan for debugging when building UI.
|
|
fn debug_bg_cyan(self) -> Self {
|
|
self.bg(hsla(160. / 360., 1., 0.5, 1.))
|
|
}
|
|
|
|
/// Sets the background color to magenta for debugging when building UI.
|
|
fn debug_bg_magenta(self) -> Self {
|
|
self.bg(hsla(300. / 360., 1., 0.5, 1.))
|
|
}
|
|
}
|
|
|
|
impl<E: Styled> StyledExt for E {}
|