Refactor text style helpers
This commit is contained in:
@@ -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<gpui::DefiniteLength>) -> 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() {
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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<GithubStepView>) ->
|
||||
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)),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -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)),
|
||||
)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user