From 6ecf629c63294414a4f0219613fdf2d417fd491b Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Wed, 8 Nov 2023 14:29:38 -0500 Subject: [PATCH] BROKEN: Checkpoint --- crates/ui2/src/components/label.rs | 4 ++- crates/ui2/src/lib.rs | 2 ++ crates/ui2/src/prelude.rs | 52 +++++++++++++++++++----------- crates/ui2/src/styled_ext.rs | 30 +++++++++++++++++ 4 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 crates/ui2/src/styled_ext.rs diff --git a/crates/ui2/src/components/label.rs b/crates/ui2/src/components/label.rs index 3346d7835a289ca7b0c950b103e4efbc4b6b832b..827ba87918a0cd4dd3f3255c8b7852436ea06a79 100644 --- a/crates/ui2/src/components/label.rs +++ b/crates/ui2/src/components/label.rs @@ -2,6 +2,8 @@ use gpui::{relative, Hsla, WindowContext}; use smallvec::SmallVec; use crate::prelude::*; +use crate::styled_ext::StyledExt; + #[derive(Default, PartialEq, Copy, Clone)] pub enum LabelColor { #[default] @@ -85,7 +87,7 @@ impl Label { .bg(LabelColor::Hidden.hsla(cx)), ) }) - .text_size(ui_text_default()) + .text_ui() .when(self.line_height_style == LineHeightStyle::UILabel, |this| { this.line_height(relative(1.)) }) diff --git a/crates/ui2/src/lib.rs b/crates/ui2/src/lib.rs index 5fb39984387e7b5b76a7ca7152ed186303bc5463..149dcd3fd04bb8f21232fbe3ffd8deaa9d7bb440 100644 --- a/crates/ui2/src/lib.rs +++ b/crates/ui2/src/lib.rs @@ -19,12 +19,14 @@ mod elevation; pub mod prelude; pub mod settings; mod static_data; +mod styled_ext; mod to_extract; pub mod utils; pub use components::*; pub use prelude::*; pub use static_data::*; +pub use styled_ext::*; pub use to_extract::*; // This needs to be fully qualified with `crate::` otherwise we get a panic diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index fc0adadb9cd890863a7fdf05988ab2e797c32864..a99f84dcfe0a65ef2819afd9a380b61160910af6 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -12,6 +12,40 @@ pub use theme2::ActiveTheme; use gpui::Hsla; use strum::EnumIter; +#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] +pub enum UITextSize { + #[default] + Default, + Small, +} + +impl UITextSize { + pub fn rems(self) -> Rems { + match self { + Self::Default => rems(0.875), + Self::Small => rems(0.75), + } + } +} + +/// 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] @@ -75,24 +109,6 @@ impl std::fmt::Display for GitStatus { } } -/// 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 DiagnosticStatus { #[default] diff --git a/crates/ui2/src/styled_ext.rs b/crates/ui2/src/styled_ext.rs new file mode 100644 index 0000000000000000000000000000000000000000..70b2a072fc7f801a0fc997c3cf5fd1a1db89d694 --- /dev/null +++ b/crates/ui2/src/styled_ext.rs @@ -0,0 +1,30 @@ +use gpui::Styled; + +use crate::UITextSize; + +pub trait StyledExt: Styled { + fn text_ui_size(self, size: UITextSize) -> Self + where + Self: Sized, + { + let size = size.rems(); + + self.text_size(size) + } + fn text_ui(self) -> Self + where + Self: Sized, + { + let size = UITextSize::default().rems(); + + self.text_size(size) + } + fn text_ui_sm(self) -> Self + where + Self: Sized, + { + let size = UITextSize::Small.rems(); + + self.text_size(size) + } +}