Change summary
crates/ui2/src/components/stack.rs | 20 ++------------
crates/ui2/src/styled_ext.rs | 45 +++++++++++++++++++++++++------
2 files changed, 39 insertions(+), 26 deletions(-)
Detailed changes
@@ -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()
}
@@ -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> {}