Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Remove the Stack trait, update StyledExt to include stacks
Nate Butlerf4abd95866b0
diff --git a/crates/ui2/src/components/stack.rs b/crates/ui2/src/components/stack.rsindex d7bd0eb04f2..d3d7a75aa76 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<V: 'static> Stack for Div<V> {}+use crate::StyledExt;/// Horizontally stacks elements.////// Sets `flex()`, `flex_row()`, `items_center()`pub fn h_stack<V: 'static>() -> Div<V> {- div().h_stack()+ div().h_flex()}/// Vertically stacks elements.////// Sets `flex()`, `flex_col()`pub fn v_stack<V: 'static>() -> Div<V> {- div().v_stack()+ div().v_flex()}diff --git a/crates/ui2/src/styled_ext.rs b/crates/ui2/src/styled_ext.rsindex f082ea93a5c..0c674d5c3c2 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<V: 'static> StyledExt for Div<V> {- 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<V: 'static> StyledExt for Div<V> {/// 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<V: 'static> StyledExt for Div<V> {/// 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<V: 'static> StyledExt for Div<V> {}