From 4ef2f0b2b9a1ff6097b0e50252a17459b428a7ca Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Wed, 8 Nov 2023 14:42:56 -0500 Subject: [PATCH] Update StyledExt to use more idiomatic method naming --- crates/ui2/src/prelude.rs | 28 +++++++++---------------- crates/ui2/src/styled_ext.rs | 40 +++++++++++++++++++++++------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index a99f84dcfe0a65ef2819afd9a380b61160910af6..0f0a22268e5ab271299c575d4a37b4e2f495ff87 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -14,8 +14,18 @@ use strum::EnumIter; #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] pub enum UITextSize { + /// The default size for UI text. + /// + /// `0.825rem` or `14px` at the default scale of `1rem` = `16px`. + /// + /// Note: The absolute size of this text will change based on a user's `ui_scale` setting. #[default] Default, + /// The small size for UI text. + /// + /// `0.75rem` or `12px` at the default scale of `1rem` = `16px`. + /// + /// Note: The absolute size of this text will change based on a user's `ui_scale` setting. Small, } @@ -28,24 +38,6 @@ impl UITextSize { } } -/// The default text size for UI text -/// -/// At a default 16px per rem, this is 14px. -/// -/// Use [`ui_text_sm`] for smaller text. -pub fn ui_text_default() -> Rems { - rems(0.875) -} - -/// The small text size for UI text -/// -/// At a default 16px per rem, this is 12px. -/// -/// Use [`ui_text_default`] for regular-sized text. -pub fn ui_text_sm() -> Rems { - rems(0.75) -} - #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] pub enum FileSystemStatus { #[default] diff --git a/crates/ui2/src/styled_ext.rs b/crates/ui2/src/styled_ext.rs index 70b2a072fc7f801a0fc997c3cf5fd1a1db89d694..f082ea93a5cb5487a0925d16d338e0eed84b52a2 100644 --- a/crates/ui2/src/styled_ext.rs +++ b/crates/ui2/src/styled_ext.rs @@ -1,28 +1,40 @@ -use gpui::Styled; +use gpui::{Div, Styled}; use crate::UITextSize; -pub trait StyledExt: Styled { - fn text_ui_size(self, size: UITextSize) -> Self - where - Self: Sized, - { +/// 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; +} + +impl StyledExt for Div { + fn text_ui_size(self, size: UITextSize) -> Self { let size = size.rems(); self.text_size(size) } - fn text_ui(self) -> Self - where - Self: Sized, - { + /// The default size for UI text. + /// + /// `0.825rem` or `14px` at the default scale of `1rem` = `16px`. + /// + /// 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 { let size = UITextSize::default().rems(); self.text_size(size) } - fn text_ui_sm(self) -> Self - where - Self: Sized, - { + /// The small size for UI text. + /// + /// `0.75rem` or `12px` at the default scale of `1rem` = `16px`. + /// + /// 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 { let size = UITextSize::Small.rems(); self.text_size(size)