From f4abd95866b0968996b38ac9370a9d5e76554ec9 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Wed, 8 Nov 2023 15:00:47 -0500 Subject: [PATCH] Remove the Stack trait, update StyledExt to include stacks Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/ui2/src/components/stack.rs | 20 ++----------- crates/ui2/src/styled_ext.rs | 45 ++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/crates/ui2/src/components/stack.rs b/crates/ui2/src/components/stack.rs index d7bd0eb04f..d3d7a75aa7 100644 --- a/crates/ui2/src/components/stack.rs +++ b/crates/ui2/src/components/stack.rs @@ -1,31 +1,17 @@ use gpui::{div, Div}; -use crate::prelude::*; - -pub trait Stack: Styled + Sized { - /// Horizontally stacks elements. - fn h_stack(self) -> Self { - self.flex().flex_row().items_center() - } - - /// Vertically stacks elements. - fn v_stack(self) -> Self { - self.flex().flex_col() - } -} - -impl Stack for Div {} +use crate::StyledExt; /// Horizontally stacks elements. /// /// Sets `flex()`, `flex_row()`, `items_center()` pub fn h_stack() -> Div { - div().h_stack() + div().h_flex() } /// Vertically stacks elements. /// /// Sets `flex()`, `flex_col()` pub fn v_stack() -> Div { - div().v_stack() + div().v_flex() } diff --git a/crates/ui2/src/styled_ext.rs b/crates/ui2/src/styled_ext.rs index f082ea93a5..0c674d5c3c 100644 --- a/crates/ui2/src/styled_ext.rs +++ b/crates/ui2/src/styled_ext.rs @@ -3,18 +3,36 @@ use gpui::{Div, Styled}; use crate::UITextSize; /// Extends [`Styled`](gpui::Styled) with Zed specific styling methods. -pub trait StyledExt { - fn text_ui_size(self, size: UITextSize) -> Self; - fn text_ui(self) -> Self; - fn text_ui_sm(self) -> Self; -} +pub trait StyledExt: Styled { + /// Horizontally stacks elements. + /// + /// Sets `flex()`, `flex_row()`, `items_center()` + fn h_flex(self) -> Self + where + Self: Sized, + { + self.flex().flex_row().items_center() + } -impl StyledExt for Div { - fn text_ui_size(self, size: UITextSize) -> Self { + /// Vertically stacks elements. + /// + /// Sets `flex()`, `flex_col()` + fn v_flex(self) -> Self + where + Self: Sized, + { + self.flex().flex_col() + } + + fn text_ui_size(self, size: UITextSize) -> Self + where + Self: Sized, + { let size = size.rems(); self.text_size(size) } + /// The default size for UI text. /// /// `0.825rem` or `14px` at the default scale of `1rem` = `16px`. @@ -22,11 +40,15 @@ impl StyledExt for Div { /// 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 { + fn text_ui(self) -> Self + where + Self: Sized, + { let size = UITextSize::default().rems(); self.text_size(size) } + /// The small size for UI text. /// /// `0.75rem` or `12px` at the default scale of `1rem` = `16px`. @@ -34,9 +56,14 @@ impl StyledExt for Div { /// 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 { + fn text_ui_sm(self) -> Self + where + Self: Sized, + { let size = UITextSize::Small.rems(); self.text_size(size) } } + +impl StyledExt for Div {}