From 9f1e051073349b183b5fea350a8fbc97421e3a0a Mon Sep 17 00:00:00 2001 From: Kenneth Date: Sat, 9 May 2026 19:31:12 +0800 Subject: [PATCH] Refactor text style helpers --- src/component/text.rs | 51 +++---------------- src/screen/dashboard/issue_list.rs | 2 +- src/screen/dashboard/sidebar.rs | 2 +- src/screen/setup_wizard/github_step.rs | 28 +++++++--- src/screen/setup_wizard/screen.rs | 8 +-- .../setup_wizard/setup_complete_step.rs | 6 ++- src/screen/setup_wizard/welcome_step.rs | 5 +- 7 files changed, 44 insertions(+), 58 deletions(-) diff --git a/src/component/text.rs b/src/component/text.rs index 6041700..4344973 100644 --- a/src/component/text.rs +++ b/src/component/text.rs @@ -4,10 +4,6 @@ use gpui::{ParentElement, Refineable as _, Styled, div}; #[derive(gpui::IntoElement)] pub(crate) struct Text { content: gpui::AnyElement, - font_weight: gpui::FontWeight, - opacity: f32, - text_align: gpui::TextAlign, - line_height: gpui::DefiniteLength, style: gpui::StyleRefinement, } @@ -20,11 +16,11 @@ impl TextContent for gpui::SharedString {} pub(crate) fn text(content: impl TextContent) -> Text { Text { content: content.into_any_element(), - font_weight: gpui::FontWeight::NORMAL, - opacity: 1., - text_align: gpui::TextAlign::Left, - line_height: gpui::relative(1.5), - style: gpui::StyleRefinement::default(), + style: gpui::StyleRefinement::default() + .font_weight(gpui::FontWeight::NORMAL) + .opacity(1.) + .text_align(gpui::TextAlign::Left) + .line_height(gpui::relative(1.5)), } } @@ -35,31 +31,6 @@ impl Styled for 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) -> Self { - self.line_height = line_height.into(); - self - } - pub(crate) fn leading_none(self) -> Self { self.line_height(gpui::relative(1.0)) } @@ -115,23 +86,13 @@ impl Text { pub(crate) fn leading_10(self) -> Self { 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 { fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement { let theme = app::current_theme(cx); - let mut div = div() - .font_weight(self.font_weight) - .opacity(self.opacity) - .text_align(self.text_align) - .line_height(self.line_height) - .child(self.content); + let mut div = div().child(self.content); div.style().refine(&self.style); if div.style().text.as_ref().and_then(|it| it.color).is_none() { diff --git a/src/screen/dashboard/issue_list.rs b/src/screen/dashboard/issue_list.rs index 9e1f1fe..3cfe505 100644 --- a/src/screen/dashboard/issue_list.rs +++ b/src/screen/dashboard/issue_list.rs @@ -145,7 +145,7 @@ impl gpui::RenderOnce for IssueListItem { text(self.title) .text_sm() .leading_tight() - .medium() + .font_weight(gpui::FontWeight::MEDIUM) .w_full() .min_w_0() .line_clamp(2), diff --git a/src/screen/dashboard/sidebar.rs b/src/screen/dashboard/sidebar.rs index ea5af53..02581a1 100644 --- a/src/screen/dashboard/sidebar.rs +++ b/src/screen/dashboard/sidebar.rs @@ -117,7 +117,7 @@ impl gpui::Render for Sidebar { .child( text("PULL REQUESTS") .text_xs() - .medium() + .font_weight(gpui::FontWeight::MEDIUM) .opacity(0.5) .pl_3() .py_1(), diff --git a/src/screen/setup_wizard/github_step.rs b/src/screen/setup_wizard/github_step.rs index a907177..f16f7a4 100644 --- a/src/screen/setup_wizard/github_step.rs +++ b/src/screen/setup_wizard/github_step.rs @@ -275,7 +275,7 @@ impl GithubStepView { .filter(|c| !c.is_empty()) .map(|c| { text(String::from(c)) - .bold() + .font_weight(gpui::FontWeight::BOLD) .text_2xl() .p_3() .font_family("CommitMono") @@ -333,14 +333,21 @@ impl GithubStepView { .flex_col() .items_center() .gap_1p5() - .child(text("Connect to GitHub").text_xl().bold()) + .child( + text("Connect to GitHub") + .text_xl() + .font_weight(gpui::FontWeight::BOLD), + ) .child(text( if self.has_copied_code { "You will be redirected to GitHub to authorize access.\nPaste the device code below into GitHub." } else { "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() .items_center() .gap_1p5() - .child(text("Connected to GitHub!").text_xl().bold()) + .child( + text("Connected to GitHub!") + .text_xl() + .font_weight(gpui::FontWeight::BOLD), + ) .child( text("Novem is now connected to your GitHub account.") .leading_tight() - .centered() + .text_center() .opacity(0.8), ) } @@ -438,7 +449,12 @@ fn connected_body(user: &api::user::User, cx: &gpui::Context) -> div() .flex() .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)), ), ) diff --git a/src/screen/setup_wizard/screen.rs b/src/screen/setup_wizard/screen.rs index 932b2d3..ca4a655 100644 --- a/src/screen/setup_wizard/screen.rs +++ b/src/screen/setup_wizard/screen.rs @@ -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::{ api, app, @@ -109,7 +109,9 @@ impl Screen { .child( text(label) .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)) }) @@ -176,7 +178,7 @@ impl gpui::Render for Screen { .top_20() .left_6() .child(font_icon(FontIcon::Cat).size_4()) - .child(text("Novem").bold()), + .child(text("Novem").font_weight(gpui::FontWeight::BOLD)), ) .child(self.step_list(cx)), ) diff --git a/src/screen/setup_wizard/setup_complete_step.rs b/src/screen/setup_wizard/setup_complete_step.rs index 205032c..95fbc6b 100644 --- a/src/screen/setup_wizard/setup_complete_step.rs +++ b/src/screen/setup_wizard/setup_complete_step.rs @@ -17,7 +17,11 @@ pub(crate) fn setup_complete_step() -> impl gpui::IntoElement { .items_center() .justify_center() .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( diff --git a/src/screen/setup_wizard/welcome_step.rs b/src/screen/setup_wizard/welcome_step.rs index 52eb657..fb0edf7 100644 --- a/src/screen/setup_wizard/welcome_step.rs +++ b/src/screen/setup_wizard/welcome_step.rs @@ -46,7 +46,10 @@ impl gpui::RenderOnce for WelcomeStep { ) .opacity(0.8), ) - .child(text("Press 'Next' to begin setup.").medium()), + .child( + text("Press 'Next' to begin setup.") + .font_weight(gpui::FontWeight::MEDIUM), + ), ) .child( div()