diff --git a/src/component/button.rs b/src/component/button.rs index 0680675..e7cc881 100644 --- a/src/component/button.rs +++ b/src/component/button.rs @@ -9,8 +9,8 @@ use crate::{app, component::text::TextContent}; pub struct Button { id: gpui::ElementId, label: Option, - leading: Option, - trailing: Option, + leading: Option gpui::AnyElement>>, + trailing: Option gpui::AnyElement>>, on_click: Option>, enabled: bool, } @@ -32,13 +32,19 @@ impl Button { self } - pub fn leading(mut self, s: gpui::Svg) -> Self { - self.leading = Some(s.size_3()); + pub fn leading(mut self, s: impl IntoElement + Styled + 'static) -> Self { + let s = s.size_3(); + self.leading = Some(Box::new(move |color| { + s.text_color(color).into_any_element() + })); self } - pub fn trailing(mut self, s: gpui::Svg) -> Self { - self.trailing = Some(s.size_3()); + pub fn trailing(mut self, s: impl IntoElement + Styled + 'static) -> Self { + let s = s.size_3(); + self.trailing = Some(Box::new(move |color| { + s.text_color(color).into_any_element() + })); self } @@ -62,21 +68,13 @@ impl gpui::RenderOnce for Button { let mut children: Vec = Vec::with_capacity(3); if let Some(leading) = self.leading { - children.push( - leading - .text_color(theme.colors.accent_text) - .into_any_element(), - ); + children.push(leading(theme.colors.accent_text)); } if let Some(label) = self.label { children.push(label); } if let Some(trailing) = self.trailing { - children.push( - trailing - .text_color(theme.colors.accent_text) - .into_any_element(), - ); + children.push(trailing(theme.colors.accent_text)); } div() diff --git a/src/component/font_icon.rs b/src/component/font_icon.rs index 550fd61..16813e1 100644 --- a/src/component/font_icon.rs +++ b/src/component/font_icon.rs @@ -1,4 +1,4 @@ -use gpui::{Styled, svg}; +use gpui::{Refineable as _, RenderOnce, Styled, svg}; use paste::paste; use crate::app; @@ -28,7 +28,33 @@ macro_rules! define_font_icons { define_font_icons!(Check, ChevronDown, FolderGit, Github, ArrowRight); -pub fn font_icon(icon: FontIcon, cx: &gpui::Context) -> gpui::Svg { - let theme = cx.global::().current_theme; - svg().path(icon_path(icon)).text_color(theme.colors.text) +#[derive(gpui::IntoElement)] +pub struct FontIconSvg { + icon: FontIcon, + style: gpui::StyleRefinement, +} + +pub fn font_icon(icon: FontIcon) -> FontIconSvg { + FontIconSvg { + icon, + style: gpui::StyleRefinement::default(), + } +} + +impl Styled for FontIconSvg { + fn style(&mut self) -> &mut gpui::StyleRefinement { + &mut self.style + } +} + +impl RenderOnce for FontIconSvg { + fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement { + let theme = app::current_theme(cx); + + let mut svg = svg() + .path(icon_path(self.icon)) + .text_color(theme.colors.text); + svg.style().refine(&self.style); + svg + } } diff --git a/src/screen/setup_wizard/github_step.rs b/src/screen/setup_wizard/github_step.rs index 2fef575..2ddda33 100644 --- a/src/screen/setup_wizard/github_step.rs +++ b/src/screen/setup_wizard/github_step.rs @@ -443,7 +443,7 @@ fn connected_body(user: &api::user::User, cx: &gpui::Context) -> .rounded_full() .bg(theme.colors.accent) .p_1() - .child(font_icon(FontIcon::Check, cx).size_4()), + .child(font_icon(FontIcon::Check).size_4()), ), ) } diff --git a/src/screen/setup_wizard/screen.rs b/src/screen/setup_wizard/screen.rs index 98f493b..fab0079 100644 --- a/src/screen/setup_wizard/screen.rs +++ b/src/screen/setup_wizard/screen.rs @@ -88,11 +88,11 @@ impl Screen { } } - fn step_list(&self, cx: &gpui::Context) -> impl gpui::IntoElement { + fn step_list(&self, _cx: &gpui::Context) -> impl gpui::IntoElement { let children: Vec = ALL_SETUP_STEPS .iter() .enumerate() - .map(|(i, step)| { + .map(|(i, step)| { let label = match step { Step::Welcome => "Welcome!", Step::ConnectToGithub => "Connect to GitHub", @@ -106,10 +106,7 @@ impl Screen { .items_center() .gap_2p5() .child(if is_completed { - font_icon(FontIcon::Check, cx) - .size_4() - .into_any_element() - .into_any_element() + font_icon(FontIcon::Check).size_4().into_any_element() } else { div().size_4().into_any_element() }) diff --git a/src/titlebar.rs b/src/titlebar.rs index ccd1f0e..336abe5 100644 --- a/src/titlebar.rs +++ b/src/titlebar.rs @@ -36,7 +36,7 @@ impl gpui::Render for TitleBar { let user_avatar = match user { QueryStatus::Err(api::Error::Unauthenticated) => div().absolute().right_2p5().child( button("login-btn") - .leading(font_icon(FontIcon::Github, cx)) + .leading(font_icon(FontIcon::Github)) .label("Login"), ), @@ -69,14 +69,14 @@ impl RepoSelector { } } -fn repo_selector(cx: &gpui::Context) -> gpui::Div { +fn repo_selector(_cx: &gpui::Context) -> gpui::Div { div() .flex() .flex_row() .items_center() .gap_1() .text_xs() - .child(font_icon(FontIcon::FolderGit, cx).size_3()) + .child(font_icon(FontIcon::FolderGit).size_3()) .child(text("test/repo")) - .child(font_icon(FontIcon::ChevronDown, cx).size_3()) + .child(font_icon(FontIcon::ChevronDown).size_3()) }