feat: port svg sizing to font icons
This commit is contained in:
@@ -9,8 +9,8 @@ use crate::{app, component::text::TextContent};
|
|||||||
pub struct Button {
|
pub struct Button {
|
||||||
id: gpui::ElementId,
|
id: gpui::ElementId,
|
||||||
label: Option<gpui::AnyElement>,
|
label: Option<gpui::AnyElement>,
|
||||||
leading: Option<gpui::Svg>,
|
leading: Option<Box<dyn FnOnce(gpui::Rgba) -> gpui::AnyElement>>,
|
||||||
trailing: Option<gpui::Svg>,
|
trailing: Option<Box<dyn FnOnce(gpui::Rgba) -> gpui::AnyElement>>,
|
||||||
on_click: Option<Box<dyn Fn(&gpui::ClickEvent, &mut gpui::Window, &mut gpui::App)>>,
|
on_click: Option<Box<dyn Fn(&gpui::ClickEvent, &mut gpui::Window, &mut gpui::App)>>,
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
}
|
}
|
||||||
@@ -32,13 +32,19 @@ impl Button {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn leading(mut self, s: gpui::Svg) -> Self {
|
pub fn leading(mut self, s: impl IntoElement + Styled + 'static) -> Self {
|
||||||
self.leading = Some(s.size_3());
|
let s = s.size_3();
|
||||||
|
self.leading = Some(Box::new(move |color| {
|
||||||
|
s.text_color(color).into_any_element()
|
||||||
|
}));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trailing(mut self, s: gpui::Svg) -> Self {
|
pub fn trailing(mut self, s: impl IntoElement + Styled + 'static) -> Self {
|
||||||
self.trailing = Some(s.size_3());
|
let s = s.size_3();
|
||||||
|
self.trailing = Some(Box::new(move |color| {
|
||||||
|
s.text_color(color).into_any_element()
|
||||||
|
}));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,21 +68,13 @@ impl gpui::RenderOnce for Button {
|
|||||||
|
|
||||||
let mut children: Vec<AnyElement> = Vec::with_capacity(3);
|
let mut children: Vec<AnyElement> = Vec::with_capacity(3);
|
||||||
if let Some(leading) = self.leading {
|
if let Some(leading) = self.leading {
|
||||||
children.push(
|
children.push(leading(theme.colors.accent_text));
|
||||||
leading
|
|
||||||
.text_color(theme.colors.accent_text)
|
|
||||||
.into_any_element(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if let Some(label) = self.label {
|
if let Some(label) = self.label {
|
||||||
children.push(label);
|
children.push(label);
|
||||||
}
|
}
|
||||||
if let Some(trailing) = self.trailing {
|
if let Some(trailing) = self.trailing {
|
||||||
children.push(
|
children.push(trailing(theme.colors.accent_text));
|
||||||
trailing
|
|
||||||
.text_color(theme.colors.accent_text)
|
|
||||||
.into_any_element(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
div()
|
div()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use gpui::{Styled, svg};
|
use gpui::{Refineable as _, RenderOnce, Styled, svg};
|
||||||
use paste::paste;
|
use paste::paste;
|
||||||
|
|
||||||
use crate::app;
|
use crate::app;
|
||||||
@@ -28,7 +28,33 @@ macro_rules! define_font_icons {
|
|||||||
|
|
||||||
define_font_icons!(Check, ChevronDown, FolderGit, Github, ArrowRight);
|
define_font_icons!(Check, ChevronDown, FolderGit, Github, ArrowRight);
|
||||||
|
|
||||||
pub fn font_icon<T>(icon: FontIcon, cx: &gpui::Context<T>) -> gpui::Svg {
|
#[derive(gpui::IntoElement)]
|
||||||
let theme = cx.global::<app::Global>().current_theme;
|
pub struct FontIconSvg {
|
||||||
svg().path(icon_path(icon)).text_color(theme.colors.text)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ fn connected_body(user: &api::user::User, cx: &gpui::Context<GithubStepView>) ->
|
|||||||
.rounded_full()
|
.rounded_full()
|
||||||
.bg(theme.colors.accent)
|
.bg(theme.colors.accent)
|
||||||
.p_1()
|
.p_1()
|
||||||
.child(font_icon(FontIcon::Check, cx).size_4()),
|
.child(font_icon(FontIcon::Check).size_4()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,11 +88,11 @@ impl Screen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn step_list(&self, cx: &gpui::Context<Self>) -> impl gpui::IntoElement {
|
fn step_list(&self, _cx: &gpui::Context<Self>) -> impl gpui::IntoElement {
|
||||||
let children: Vec<gpui::Div> = ALL_SETUP_STEPS
|
let children: Vec<gpui::Div> = ALL_SETUP_STEPS
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, step)| {
|
.map(|(i, step)| {
|
||||||
let label = match step {
|
let label = match step {
|
||||||
Step::Welcome => "Welcome!",
|
Step::Welcome => "Welcome!",
|
||||||
Step::ConnectToGithub => "Connect to GitHub",
|
Step::ConnectToGithub => "Connect to GitHub",
|
||||||
@@ -106,10 +106,7 @@ impl Screen {
|
|||||||
.items_center()
|
.items_center()
|
||||||
.gap_2p5()
|
.gap_2p5()
|
||||||
.child(if is_completed {
|
.child(if is_completed {
|
||||||
font_icon(FontIcon::Check, cx)
|
font_icon(FontIcon::Check).size_4().into_any_element()
|
||||||
.size_4()
|
|
||||||
.into_any_element()
|
|
||||||
.into_any_element()
|
|
||||||
} else {
|
} else {
|
||||||
div().size_4().into_any_element()
|
div().size_4().into_any_element()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ impl gpui::Render for TitleBar {
|
|||||||
let user_avatar = match user {
|
let user_avatar = match user {
|
||||||
QueryStatus::Err(api::Error::Unauthenticated) => div().absolute().right_2p5().child(
|
QueryStatus::Err(api::Error::Unauthenticated) => div().absolute().right_2p5().child(
|
||||||
button("login-btn")
|
button("login-btn")
|
||||||
.leading(font_icon(FontIcon::Github, cx))
|
.leading(font_icon(FontIcon::Github))
|
||||||
.label("Login"),
|
.label("Login"),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -69,14 +69,14 @@ impl RepoSelector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn repo_selector<T: 'static>(cx: &gpui::Context<T>) -> gpui::Div {
|
fn repo_selector<T: 'static>(_cx: &gpui::Context<T>) -> gpui::Div {
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
.flex_row()
|
.flex_row()
|
||||||
.items_center()
|
.items_center()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.child(font_icon(FontIcon::FolderGit, cx).size_3())
|
.child(font_icon(FontIcon::FolderGit).size_3())
|
||||||
.child(text("test/repo"))
|
.child(text("test/repo"))
|
||||||
.child(font_icon(FontIcon::ChevronDown, cx).size_3())
|
.child(font_icon(FontIcon::ChevronDown).size_3())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user