From 56cfc60875f6105fb3bd2fece6427bdaa1cbde4e Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Sun, 9 Feb 2025 15:23:39 -0300 Subject: [PATCH] ui: Add `buffer_font` method to labels (#24479) Now you don't need to wrap the `Label` in a `div` anymore Release Notes: - N/A Co-authored-by: Danilo --- crates/ui/src/components/label/highlighted_label.rs | 5 +++++ crates/ui/src/components/label/label.rs | 5 +++++ crates/ui/src/components/label/label_like.rs | 10 ++++++++++ crates/ui/src/styles/color.rs | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/crates/ui/src/components/label/highlighted_label.rs b/crates/ui/src/components/label/highlighted_label.rs index d528f47218a46689611329360574d61613f9d31f..14ea7a5cf165a8867d95e15f6c136577980a3a58 100644 --- a/crates/ui/src/components/label/highlighted_label.rs +++ b/crates/ui/src/components/label/highlighted_label.rs @@ -75,6 +75,11 @@ impl LabelCommon for HighlightedLabel { self.base = self.base.single_line(); self } + + fn buffer_font(mut self, cx: &App) -> Self { + self.base = self.base.buffer_font(cx); + self + } } pub fn highlight_ranges( diff --git a/crates/ui/src/components/label/label.rs b/crates/ui/src/components/label/label.rs index 5f170b9a1520363893bef78b520242bc83c0f6eb..ff2687d0478a1d5e2a804a7198e8cea91e4ef1a2 100644 --- a/crates/ui/src/components/label/label.rs +++ b/crates/ui/src/components/label/label.rs @@ -172,6 +172,11 @@ impl LabelCommon for Label { self.base = self.base.single_line(); self } + + fn buffer_font(mut self, cx: &App) -> Self { + self.base = self.base.buffer_font(cx); + self + } } impl RenderOnce for Label { diff --git a/crates/ui/src/components/label/label_like.rs b/crates/ui/src/components/label/label_like.rs index c9674f10a0173beb8823ceacc20bc99cfadab8d9..fad24d8699c0cbc81034cce48389d10d5e71b223 100644 --- a/crates/ui/src/components/label/label_like.rs +++ b/crates/ui/src/components/label/label_like.rs @@ -55,6 +55,9 @@ pub trait LabelCommon { /// Sets the label to render as a single line. fn single_line(self) -> Self; + + /// Sets the font to the buffer's + fn buffer_font(self, cx: &App) -> Self; } #[derive(IntoElement)] @@ -159,6 +162,13 @@ impl LabelCommon for LabelLike { self.single_line = true; self } + + fn buffer_font(mut self, cx: &App) -> Self { + self.base = self + .base + .font(theme::ThemeSettings::get_global(cx).buffer_font.clone()); + self + } } impl ParentElement for LabelLike { diff --git a/crates/ui/src/styles/color.rs b/crates/ui/src/styles/color.rs index a8cf1d51e50adf8d9733fb77ace01791300e6903..0d234ad50d9bcd6f1a39f1f052d8a361479664f7 100644 --- a/crates/ui/src/styles/color.rs +++ b/crates/ui/src/styles/color.rs @@ -86,3 +86,9 @@ impl Color { } } } + +impl From for Color { + fn from(color: Hsla) -> Self { + Color::Custom(color) + } +}