refactor: impl Styled for Text

This commit is contained in:
2026-05-08 02:29:38 +08:00
parent 19769a7b75
commit 5de1cbaec2
5 changed files with 22 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
use crate::app; use crate::app;
use gpui::{ParentElement, Styled, div}; use gpui::{ParentElement, Refineable as _, Styled, div};
#[derive(gpui::IntoElement)] #[derive(gpui::IntoElement)]
pub(crate) struct Text { pub(crate) struct Text {
@@ -10,7 +10,7 @@ pub(crate) struct Text {
text_size: Option<gpui::AbsoluteLength>, text_size: Option<gpui::AbsoluteLength>,
text_color: Option<gpui::Hsla>, text_color: Option<gpui::Hsla>,
line_height: gpui::DefiniteLength, line_height: gpui::DefiniteLength,
styled: Option<Box<dyn Fn(gpui::Div) -> gpui::Div>>, style: gpui::StyleRefinement,
} }
pub(crate) trait TextContent: gpui::IntoElement {} pub(crate) trait TextContent: gpui::IntoElement {}
@@ -28,7 +28,13 @@ pub(crate) fn text(content: impl TextContent) -> Text {
text_size: None, text_size: None,
text_color: None, text_color: None,
line_height: gpui::relative(1.5), line_height: gpui::relative(1.5),
styled: None, style: gpui::StyleRefinement::default(),
}
}
impl Styled for Text {
fn style(&mut self) -> &mut gpui::StyleRefinement {
&mut self.style
} }
} }
@@ -152,11 +158,6 @@ impl Text {
self.line_height(gpui::rems(2.5)) self.line_height(gpui::rems(2.5))
} }
pub(crate) fn styled(mut self, styled: impl Fn(gpui::Div) -> gpui::Div + 'static) -> Self {
self.styled = Some(Box::new(styled));
self
}
pub(crate) fn centered(mut self) -> Self { pub(crate) fn centered(mut self) -> Self {
self.text_align = gpui::TextAlign::Center; self.text_align = gpui::TextAlign::Center;
self self
@@ -176,9 +177,7 @@ impl gpui::RenderOnce for Text {
if let Some(text_size) = self.text_size { if let Some(text_size) = self.text_size {
div = div.text_size(text_size); div = div.text_size(text_size);
} }
if let Some(styled) = self.styled { div.style().refine(&self.style);
div = styled(div);
}
div div
} }
} }

View File

@@ -146,7 +146,9 @@ impl gpui::RenderOnce for IssueListItem {
.text_sm() .text_sm()
.leading_tight() .leading_tight()
.medium() .medium()
.styled(|it| it.w_full().min_w_0().line_clamp(2)), .w_full()
.min_w_0()
.line_clamp(2),
) )
.child(description_text), .child(description_text),
) )

View File

@@ -119,7 +119,8 @@ impl gpui::Render for Sidebar {
.text_xs() .text_xs()
.medium() .medium()
.opacity(0.5) .opacity(0.5)
.styled(|it| it.pl_3().py_1()), .pl_3()
.py_1(),
) )
.children(pull_request_sidebar_items), .children(pull_request_sidebar_items),
) )

View File

@@ -277,14 +277,12 @@ impl GithubStepView {
text(String::from(c)) text(String::from(c))
.bold() .bold()
.text_2xl() .text_2xl()
.styled(move |it| { .p_3()
it.p_3() .font_family("CommitMono")
.font_family("CommitMono") .border_1()
.border_1() .border_color(border_color)
.border_color(border_color) .rounded_lg()
.rounded_lg() .bg(bg_color)
.bg(bg_color)
})
.when(is_loading_code, |it| it.opacity(0.5)) .when(is_loading_code, |it| it.opacity(0.5))
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View File

@@ -16,7 +16,7 @@ pub(crate) fn setup_complete_step() -> impl gpui::IntoElement {
.flex_col() .flex_col()
.items_center() .items_center()
.justify_center() .justify_center()
.child(text("ദ്ദി/ᐠ - ⩊ -マ.ᐟ").text_2xl().styled(|it| it.mb_4())) .child(text("ദ്ദി/ᐠ - ⩊ -マ.ᐟ").text_2xl().mb_4())
.child(text("Setup complete!").bold().text_2xl()) .child(text("Setup complete!").bold().text_2xl())
.child(text("You can now start using Novem.").opacity(0.8)), .child(text("You can now start using Novem.").opacity(0.8)),
) )