Merge branch 'main' into dispatch-tree
This commit is contained in:
commit
f464d69ff8
20 changed files with 2801 additions and 2730 deletions
|
@ -3,6 +3,7 @@ mod button;
|
|||
mod checkbox;
|
||||
mod context_menu;
|
||||
mod details;
|
||||
mod divider;
|
||||
mod elevated_surface;
|
||||
mod facepile;
|
||||
mod icon;
|
||||
|
@ -31,6 +32,7 @@ pub use button::*;
|
|||
pub use checkbox::*;
|
||||
pub use context_menu::*;
|
||||
pub use details::*;
|
||||
pub use divider::*;
|
||||
pub use elevated_surface::*;
|
||||
pub use facepile::*;
|
||||
pub use icon::*;
|
||||
|
|
46
crates/ui2/src/components/divider.rs
Normal file
46
crates/ui2/src/components/divider.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
enum DividerDirection {
|
||||
Horizontal,
|
||||
Vertical,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Divider {
|
||||
direction: DividerDirection,
|
||||
inset: bool,
|
||||
}
|
||||
|
||||
impl Divider {
|
||||
pub fn horizontal() -> Self {
|
||||
Self {
|
||||
direction: DividerDirection::Horizontal,
|
||||
inset: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vertical() -> Self {
|
||||
Self {
|
||||
direction: DividerDirection::Vertical,
|
||||
inset: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inset(mut self) -> Self {
|
||||
self.inset = true;
|
||||
self
|
||||
}
|
||||
|
||||
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
|
||||
div()
|
||||
.map(|this| match self.direction {
|
||||
DividerDirection::Horizontal => {
|
||||
this.h_px().w_full().when(self.inset, |this| this.mx_1p5())
|
||||
}
|
||||
DividerDirection::Vertical => {
|
||||
this.w_px().h_full().when(self.inset, |this| this.my_1p5())
|
||||
}
|
||||
})
|
||||
.bg(cx.theme().colors().border_variant)
|
||||
}
|
||||
}
|
|
@ -24,5 +24,5 @@ pub fn elevated_surface<V: 'static>(level: ElevationIndex, cx: &mut ViewContext<
|
|||
}
|
||||
|
||||
pub fn modal<V>(cx: &mut ViewContext<V>) -> Div<V> {
|
||||
elevated_surface(ElevationIndex::ModalSurfaces, cx)
|
||||
elevated_surface(ElevationIndex::ModalSurface, cx)
|
||||
}
|
||||
|
|
|
@ -401,7 +401,7 @@ impl List {
|
|||
v_stack()
|
||||
.w_full()
|
||||
.py_1()
|
||||
.children(self.header.map(|header| header))
|
||||
.children(self.header)
|
||||
.child(list_content)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ Material Design 3 has a some great visualizations of elevation that may be helpf
|
|||
|
||||
The app background constitutes the lowest elevation layer, appearing behind all other surfaces and components. It is predominantly used for the background color of the app.
|
||||
|
||||
### UI Surface
|
||||
### Surface
|
||||
|
||||
The UI Surface, located above the app background, is the standard level for all elements
|
||||
The Surface elevation level, located above the app background, is the standard level for all elements
|
||||
|
||||
Example Elements: Title Bar, Panel, Tab Bar, Editor
|
||||
|
||||
|
|
|
@ -11,43 +11,53 @@ pub enum Elevation {
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ElevationIndex {
|
||||
AppBackground,
|
||||
UISurface,
|
||||
Background,
|
||||
Surface,
|
||||
ElevatedSurface,
|
||||
Wash,
|
||||
ModalSurfaces,
|
||||
ModalSurface,
|
||||
DraggedElement,
|
||||
}
|
||||
|
||||
impl ElevationIndex {
|
||||
pub fn z_index(self) -> u32 {
|
||||
match self {
|
||||
ElevationIndex::AppBackground => 0,
|
||||
ElevationIndex::UISurface => 100,
|
||||
ElevationIndex::Background => 0,
|
||||
ElevationIndex::Surface => 100,
|
||||
ElevationIndex::ElevatedSurface => 200,
|
||||
ElevationIndex::Wash => 300,
|
||||
ElevationIndex::ModalSurfaces => 400,
|
||||
ElevationIndex::ModalSurface => 400,
|
||||
ElevationIndex::DraggedElement => 900,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shadow(self) -> SmallVec<[BoxShadow; 2]> {
|
||||
match self {
|
||||
ElevationIndex::AppBackground => smallvec![],
|
||||
ElevationIndex::Surface => smallvec![],
|
||||
|
||||
ElevationIndex::UISurface => smallvec![BoxShadow {
|
||||
ElevationIndex::ElevatedSurface => smallvec![BoxShadow {
|
||||
color: hsla(0., 0., 0., 0.12),
|
||||
offset: point(px(0.), px(1.)),
|
||||
blur_radius: px(3.),
|
||||
spread_radius: px(0.),
|
||||
}],
|
||||
|
||||
_ => smallvec![BoxShadow {
|
||||
color: hsla(0., 0., 0., 0.32),
|
||||
offset: point(px(1.), px(3.)),
|
||||
blur_radius: px(12.),
|
||||
spread_radius: px(0.),
|
||||
}],
|
||||
ElevationIndex::ModalSurface => smallvec![
|
||||
BoxShadow {
|
||||
color: hsla(0., 0., 0., 0.12),
|
||||
offset: point(px(0.), px(1.)),
|
||||
blur_radius: px(3.),
|
||||
spread_radius: px(0.),
|
||||
},
|
||||
BoxShadow {
|
||||
color: hsla(0., 0., 0., 0.16),
|
||||
offset: point(px(3.), px(1.)),
|
||||
blur_radius: px(12.),
|
||||
spread_radius: px(0.),
|
||||
},
|
||||
],
|
||||
|
||||
_ => smallvec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
use gpui::{Div, ElementInteractivity, KeyDispatch, Styled};
|
||||
use gpui::{Div, ElementInteractivity, KeyDispatch, Styled, UniformList, ViewContext};
|
||||
use theme2::ActiveTheme;
|
||||
|
||||
use crate::UITextSize;
|
||||
use crate::{ElevationIndex, UITextSize};
|
||||
|
||||
fn elevated<E: Styled, V: 'static>(this: E, cx: &mut ViewContext<V>, index: ElevationIndex) -> E {
|
||||
this.bg(cx.theme().colors().elevated_surface_background)
|
||||
.rounded_lg()
|
||||
.border()
|
||||
.border_color(cx.theme().colors().border_variant)
|
||||
.shadow(index.shadow())
|
||||
}
|
||||
|
||||
/// Extends [`Styled`](gpui::Styled) with Zed specific styling methods.
|
||||
pub trait StyledExt: Styled {
|
||||
pub trait StyledExt: Styled + Sized {
|
||||
/// Horizontally stacks elements.
|
||||
///
|
||||
/// Sets `flex()`, `flex_row()`, `items_center()`
|
||||
fn h_flex(self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn h_flex(self) -> Self {
|
||||
self.flex().flex_row().items_center()
|
||||
}
|
||||
|
||||
/// Vertically stacks elements.
|
||||
///
|
||||
/// Sets `flex()`, `flex_col()`
|
||||
fn v_flex(self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn v_flex(self) -> Self {
|
||||
self.flex().flex_col()
|
||||
}
|
||||
|
||||
fn text_ui_size(self, size: UITextSize) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn text_ui_size(self, size: UITextSize) -> Self {
|
||||
let size = size.rems();
|
||||
|
||||
self.text_size(size)
|
||||
|
@ -40,10 +40,7 @@ pub trait StyledExt: Styled {
|
|||
/// Note: The absolute size of this text will change based on a user's `ui_scale` setting.
|
||||
///
|
||||
/// Use [`text_ui_sm`] for regular-sized text.
|
||||
fn text_ui(self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn text_ui(self) -> Self {
|
||||
let size = UITextSize::default().rems();
|
||||
|
||||
self.text_size(size)
|
||||
|
@ -56,14 +53,44 @@ pub trait StyledExt: Styled {
|
|||
/// Note: The absolute size of this text will change based on a user's `ui_scale` setting.
|
||||
///
|
||||
/// Use [`text_ui`] for regular-sized text.
|
||||
fn text_ui_sm(self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn text_ui_sm(self) -> Self {
|
||||
let size = UITextSize::Small.rems();
|
||||
|
||||
self.text_size(size)
|
||||
}
|
||||
|
||||
/// The [`Surface`](ui2::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<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
|
||||
elevated(self, cx, ElevationIndex::Surface)
|
||||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
|
||||
///
|
||||
/// Examples: Notifications, Palettes, Detached/Floating Windows, Detached/Floating Panels
|
||||
fn elevation_2<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
|
||||
elevated(self, cx, ElevationIndex::ElevatedSurface)
|
||||
}
|
||||
|
||||
// There is no elevation 3, as the third elevation level is reserved for wash layers. See [`Elevation`](ui2::Elevation).
|
||||
|
||||
/// 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`](ui2::ElevationIndex::ElevatedSurface) layer.
|
||||
///
|
||||
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
|
||||
///
|
||||
/// Examples: Settings Modal, Channel Management, Wizards/Setup UI, Dialogs
|
||||
fn elevation_4<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
|
||||
elevated(self, cx, ElevationIndex::ModalSurface)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V, I, F> StyledExt for Div<V, I, F>
|
||||
|
@ -72,3 +99,5 @@ where
|
|||
F: KeyDispatch<V>,
|
||||
{
|
||||
}
|
||||
|
||||
impl<V> StyledExt for UniformList<V> {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue