From 6e11044e9ef6ce20d7db0a4eacfa60ebac7c94f3 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Wed, 8 Nov 2023 12:57:24 -0500 Subject: [PATCH] add `ui_text_size` functions --- crates/ui2/src/components/label.rs | 4 ++-- crates/ui2/src/prelude.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/ui2/src/components/label.rs b/crates/ui2/src/components/label.rs index dd078d2331305dcfd87a66a52c290b0bfe8cb1fa..3346d7835a289ca7b0c950b103e4efbc4b6b832b 100644 --- a/crates/ui2/src/components/label.rs +++ b/crates/ui2/src/components/label.rs @@ -1,4 +1,4 @@ -use gpui::{relative, rems, Hsla, WindowContext}; +use gpui::{relative, Hsla, WindowContext}; use smallvec::SmallVec; use crate::prelude::*; @@ -85,7 +85,7 @@ impl Label { .bg(LabelColor::Hidden.hsla(cx)), ) }) - .text_size(rems(1.)) + .text_size(ui_text_default()) .when(self.line_height_style == LineHeightStyle::UILabel, |this| { this.line_height(relative(1.)) }) diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index 3f179210eb3fc5c8329ea3cde110f2f5b33e7ee0..fc0adadb9cd890863a7fdf05988ab2e797c32864 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -1,3 +1,5 @@ +use gpui::rems; +use gpui::Rems; pub use gpui::{ div, Component, Element, ElementId, ParentElement, SharedString, StatefulInteractive, StatelessInteractive, Styled, ViewContext, WindowContext, @@ -73,6 +75,24 @@ 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]