Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Update StyledExt to use more idiomatic method naming

Nate Butler4ef2f0b2b9a1
diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs
index a99f84dcfe0..0f0a22268e5 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 70b2a072fc7..f082ea93a5c 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<V: 'static> StyledExt for Div<V> {
+ 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)