fix: text theme color not applied

This commit is contained in:
2026-05-09 18:59:32 +08:00
parent 5de1cbaec2
commit 6eabc6a0ec

View File

@@ -7,8 +7,6 @@ pub(crate) struct Text {
font_weight: gpui::FontWeight, font_weight: gpui::FontWeight,
opacity: f32, opacity: f32,
text_align: gpui::TextAlign, text_align: gpui::TextAlign,
text_size: Option<gpui::AbsoluteLength>,
text_color: Option<gpui::Hsla>,
line_height: gpui::DefiniteLength, line_height: gpui::DefiniteLength,
style: gpui::StyleRefinement, style: gpui::StyleRefinement,
} }
@@ -25,8 +23,6 @@ pub(crate) fn text(content: impl TextContent) -> Text {
font_weight: gpui::FontWeight::NORMAL, font_weight: gpui::FontWeight::NORMAL,
opacity: 1., opacity: 1.,
text_align: gpui::TextAlign::Left, text_align: gpui::TextAlign::Left,
text_size: None,
text_color: None,
line_height: gpui::relative(1.5), line_height: gpui::relative(1.5),
style: gpui::StyleRefinement::default(), style: gpui::StyleRefinement::default(),
} }
@@ -59,44 +55,6 @@ impl Text {
self self
} }
pub(crate) fn text_size(mut self, size: impl Into<gpui::AbsoluteLength>) -> Self {
self.text_size = Some(size.into());
self
}
pub(crate) fn text_xs(self) -> Self {
self.text_size(gpui::rems(0.75))
}
pub(crate) fn text_sm(self) -> Self {
self.text_size(gpui::rems(0.875))
}
pub(crate) fn text_base(self) -> Self {
self.text_size(gpui::rems(1.0))
}
pub(crate) fn text_lg(self) -> Self {
self.text_size(gpui::rems(1.125))
}
pub(crate) fn text_xl(self) -> Self {
self.text_size(gpui::rems(1.25))
}
pub(crate) fn text_2xl(self) -> Self {
self.text_size(gpui::rems(1.5))
}
pub(crate) fn text_3xl(self) -> Self {
self.text_size(gpui::rems(1.875))
}
pub(crate) fn text_color(mut self, color: impl Into<gpui::Hsla>) -> Self {
self.text_color = Some(color.into());
self
}
pub(crate) fn line_height(mut self, line_height: impl Into<gpui::DefiniteLength>) -> Self { pub(crate) fn line_height(mut self, line_height: impl Into<gpui::DefiniteLength>) -> Self {
self.line_height = line_height.into(); self.line_height = line_height.into();
self self
@@ -167,17 +125,20 @@ impl Text {
impl gpui::RenderOnce for Text { impl gpui::RenderOnce for Text {
fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement { fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement {
let theme = app::current_theme(cx); let theme = app::current_theme(cx);
let mut div = div() let mut div = div()
.text_color(self.text_color.unwrap_or(theme.colors.text.into()))
.font_weight(self.font_weight) .font_weight(self.font_weight)
.opacity(self.opacity) .opacity(self.opacity)
.text_align(self.text_align) .text_align(self.text_align)
.line_height(self.line_height) .line_height(self.line_height)
.child(self.content); .child(self.content);
if let Some(text_size) = self.text_size {
div = div.text_size(text_size);
}
div.style().refine(&self.style); div.style().refine(&self.style);
if div.style().text.as_ref().and_then(|it| it.color).is_none() {
// if no text color override, use theme text color
div = div.text_color(theme.colors.text);
}
div div
} }
} }