From 4c278bfabc117fa41a16f98ace8a97f5b55c7dfd Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 26 Jun 2024 17:25:26 +0800 Subject: [PATCH] Add `span` method, fix primary button text color --- crates/ui/src/button.rs | 4 +++- crates/ui/src/label.rs | 8 +++----- crates/ui/src/lib.rs | 1 + crates/ui/src/stock.rs | 7 ++++++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/ui/src/button.rs b/crates/ui/src/button.rs index 52ba733f..870739b8 100644 --- a/crates/ui/src/button.rs +++ b/crates/ui/src/button.rs @@ -6,6 +6,7 @@ use gpui::{ use crate::{ label::Label, + span, theme::{ActiveTheme, Colorize as _, ThemeMode}, Clickable, Disableable, Selectable, }; @@ -175,7 +176,8 @@ impl RenderOnce for Button { normal_style.fg }; - Label::new(self.label) + span() + .child(self.label) .text_color(text_color) .map(|this| match self.size { ButtonSize::Small => this.text_sm(), diff --git a/crates/ui/src/label.rs b/crates/ui/src/label.rs index 834b8ffb..c7e6aa4e 100644 --- a/crates/ui/src/label.rs +++ b/crates/ui/src/label.rs @@ -1,6 +1,6 @@ use gpui::{ div, prelude::FluentBuilder as _, px, AbsoluteLength, DefiniteLength, Div, Hsla, IntoElement, - ParentElement, RenderOnce, SharedString, Styled, WindowContext, + ParentElement, RenderOnce, SharedString, Styled, TextStyleRefinement, WindowContext, }; use crate::theme::ActiveTheme; @@ -35,8 +35,6 @@ impl Styled for Label { impl RenderOnce for Label { fn render(self, cx: &mut WindowContext) -> impl IntoElement { - let theme = cx.theme(); - let text = if !self.multiple_lines { SharedString::from(self.label.replace('\n', "␤")) } else { @@ -44,8 +42,8 @@ impl RenderOnce for Label { }; self.base - .text_color(theme.foreground) - .text_size(px(theme.font_size)) + .text_color(cx.theme().foreground) + .text_size(px(cx.theme().font_size)) .child(text) } } diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index 26708e8e..08508f30 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -16,6 +16,7 @@ pub mod theme; pub mod title_bar; pub use styled_ext::StyledExt; pub mod divider; +pub mod dropdown; pub mod picker; pub mod switch; pub mod tab; diff --git a/crates/ui/src/stock.rs b/crates/ui/src/stock.rs index 91f09d07..5e33a4b6 100644 --- a/crates/ui/src/stock.rs +++ b/crates/ui/src/stock.rs @@ -1,5 +1,5 @@ use crate::StyledExt as _; -use gpui::{div, Div}; +use gpui::{div, Div, Styled}; /// Horizontally stacks elements. Sets `flex()`, `flex_row()`, `items_center()` #[track_caller] @@ -12,3 +12,8 @@ pub fn h_flex() -> Div { pub fn v_flex() -> Div { div().v_flex() } + +/// A horizontal divider. Sets `h_0.5()`, `bg()`, `bg_gray()` +pub fn span() -> Div { + div().w_auto() +}