Refactor text style helpers

This commit is contained in:
2026-05-09 19:31:12 +08:00
parent 6eabc6a0ec
commit 9f1e051073
7 changed files with 44 additions and 58 deletions

View File

@@ -4,10 +4,6 @@ use gpui::{ParentElement, Refineable as _, Styled, div};
#[derive(gpui::IntoElement)] #[derive(gpui::IntoElement)]
pub(crate) struct Text { pub(crate) struct Text {
content: gpui::AnyElement, content: gpui::AnyElement,
font_weight: gpui::FontWeight,
opacity: f32,
text_align: gpui::TextAlign,
line_height: gpui::DefiniteLength,
style: gpui::StyleRefinement, style: gpui::StyleRefinement,
} }
@@ -20,11 +16,11 @@ impl TextContent for gpui::SharedString {}
pub(crate) fn text(content: impl TextContent) -> Text { pub(crate) fn text(content: impl TextContent) -> Text {
Text { Text {
content: content.into_any_element(), content: content.into_any_element(),
font_weight: gpui::FontWeight::NORMAL, style: gpui::StyleRefinement::default()
opacity: 1., .font_weight(gpui::FontWeight::NORMAL)
text_align: gpui::TextAlign::Left, .opacity(1.)
line_height: gpui::relative(1.5), .text_align(gpui::TextAlign::Left)
style: gpui::StyleRefinement::default(), .line_height(gpui::relative(1.5)),
} }
} }
@@ -35,31 +31,6 @@ impl Styled for Text {
} }
impl Text { impl Text {
pub(crate) fn light(mut self) -> Self {
self.font_weight = gpui::FontWeight::LIGHT;
self
}
pub(crate) fn medium(mut self) -> Self {
self.font_weight = gpui::FontWeight::MEDIUM;
self
}
pub(crate) fn bold(mut self) -> Self {
self.font_weight = gpui::FontWeight::BOLD;
self
}
pub(crate) fn opacity(mut self, opacity: f32) -> Self {
self.opacity = opacity;
self
}
pub(crate) fn line_height(mut self, line_height: impl Into<gpui::DefiniteLength>) -> Self {
self.line_height = line_height.into();
self
}
pub(crate) fn leading_none(self) -> Self { pub(crate) fn leading_none(self) -> Self {
self.line_height(gpui::relative(1.0)) self.line_height(gpui::relative(1.0))
} }
@@ -115,23 +86,13 @@ impl Text {
pub(crate) fn leading_10(self) -> Self { pub(crate) fn leading_10(self) -> Self {
self.line_height(gpui::rems(2.5)) self.line_height(gpui::rems(2.5))
} }
pub(crate) fn centered(mut self) -> Self {
self.text_align = gpui::TextAlign::Center;
self
}
} }
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().child(self.content);
.font_weight(self.font_weight)
.opacity(self.opacity)
.text_align(self.text_align)
.line_height(self.line_height)
.child(self.content);
div.style().refine(&self.style); div.style().refine(&self.style);
if div.style().text.as_ref().and_then(|it| it.color).is_none() { if div.style().text.as_ref().and_then(|it| it.color).is_none() {

View File

@@ -145,7 +145,7 @@ impl gpui::RenderOnce for IssueListItem {
text(self.title) text(self.title)
.text_sm() .text_sm()
.leading_tight() .leading_tight()
.medium() .font_weight(gpui::FontWeight::MEDIUM)
.w_full() .w_full()
.min_w_0() .min_w_0()
.line_clamp(2), .line_clamp(2),

View File

@@ -117,7 +117,7 @@ impl gpui::Render for Sidebar {
.child( .child(
text("PULL REQUESTS") text("PULL REQUESTS")
.text_xs() .text_xs()
.medium() .font_weight(gpui::FontWeight::MEDIUM)
.opacity(0.5) .opacity(0.5)
.pl_3() .pl_3()
.py_1(), .py_1(),

View File

@@ -275,7 +275,7 @@ impl GithubStepView {
.filter(|c| !c.is_empty()) .filter(|c| !c.is_empty())
.map(|c| { .map(|c| {
text(String::from(c)) text(String::from(c))
.bold() .font_weight(gpui::FontWeight::BOLD)
.text_2xl() .text_2xl()
.p_3() .p_3()
.font_family("CommitMono") .font_family("CommitMono")
@@ -333,14 +333,21 @@ impl GithubStepView {
.flex_col() .flex_col()
.items_center() .items_center()
.gap_1p5() .gap_1p5()
.child(text("Connect to GitHub").text_xl().bold()) .child(
text("Connect to GitHub")
.text_xl()
.font_weight(gpui::FontWeight::BOLD),
)
.child(text( .child(text(
if self.has_copied_code { if self.has_copied_code {
"You will be redirected to GitHub to authorize access.\nPaste the device code below into GitHub." "You will be redirected to GitHub to authorize access.\nPaste the device code below into GitHub."
} else { } else {
"You will be redirected to GitHub to authorize access.\nCopy the device code below into GitHub." "You will be redirected to GitHub to authorize access.\nCopy the device code below into GitHub."
} }
).leading_tight().centered().opacity(0.8)) )
.leading_tight()
.text_center()
.opacity(0.8))
} }
} }
@@ -394,11 +401,15 @@ fn connected_header() -> gpui::Div {
.flex_col() .flex_col()
.items_center() .items_center()
.gap_1p5() .gap_1p5()
.child(text("Connected to GitHub!").text_xl().bold()) .child(
text("Connected to GitHub!")
.text_xl()
.font_weight(gpui::FontWeight::BOLD),
)
.child( .child(
text("Novem is now connected to your GitHub account.") text("Novem is now connected to your GitHub account.")
.leading_tight() .leading_tight()
.centered() .text_center()
.opacity(0.8), .opacity(0.8),
) )
} }
@@ -438,7 +449,12 @@ fn connected_body(user: &api::user::User, cx: &gpui::Context<GithubStepView>) ->
div() div()
.flex() .flex()
.flex_col() .flex_col()
.child(text(display_name).medium().text_xl().leading_tight()) .child(
text(display_name)
.font_weight(gpui::FontWeight::MEDIUM)
.text_xl()
.leading_tight(),
)
.child(text(user.login.clone()).text_sm().opacity(0.5)), .child(text(user.login.clone()).text_sm().opacity(0.5)),
), ),
) )

View File

@@ -1,4 +1,4 @@
use gpui::{AppContext, IntoElement, ParentElement, Styled, div, prelude::FluentBuilder, rems}; use gpui::{AppContext, IntoElement, ParentElement, Styled, div, prelude::FluentBuilder};
use crate::{ use crate::{
api, app, api, app,
@@ -109,7 +109,9 @@ impl Screen {
.child( .child(
text(label) text(label)
.leading_tight() .leading_tight()
.when(self.current_step == *step, |it| it.bold()), .when(self.current_step == *step, |it| {
it.font_weight(gpui::FontWeight::BOLD)
}),
) )
.when(!is_current, |it| it.opacity(0.5)) .when(!is_current, |it| it.opacity(0.5))
}) })
@@ -176,7 +178,7 @@ impl gpui::Render for Screen {
.top_20() .top_20()
.left_6() .left_6()
.child(font_icon(FontIcon::Cat).size_4()) .child(font_icon(FontIcon::Cat).size_4())
.child(text("Novem").bold()), .child(text("Novem").font_weight(gpui::FontWeight::BOLD)),
) )
.child(self.step_list(cx)), .child(self.step_list(cx)),
) )

View File

@@ -17,7 +17,11 @@ pub(crate) fn setup_complete_step() -> impl gpui::IntoElement {
.items_center() .items_center()
.justify_center() .justify_center()
.child(text("ദ്ദി/ᐠ - ⩊ -マ.ᐟ").text_2xl().mb_4()) .child(text("ദ്ദി/ᐠ - ⩊ -マ.ᐟ").text_2xl().mb_4())
.child(text("Setup complete!").bold().text_2xl()) .child(
text("Setup complete!")
.font_weight(gpui::FontWeight::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)),
) )
.child( .child(

View File

@@ -46,7 +46,10 @@ impl gpui::RenderOnce for WelcomeStep {
) )
.opacity(0.8), .opacity(0.8),
) )
.child(text("Press 'Next' to begin setup.").medium()), .child(
text("Press 'Next' to begin setup.")
.font_weight(gpui::FontWeight::MEDIUM),
),
) )
.child( .child(
div() div()