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 {
|
||||
id: gpui::ElementId,
|
||||
label: Option<gpui::AnyElement>,
|
||||
leading: Option<gpui::Svg>,
|
||||
trailing: Option<gpui::Svg>,
|
||||
leading: Option<Box<dyn FnOnce(gpui::Rgba) -> gpui::AnyElement>>,
|
||||
trailing: Option<Box<dyn FnOnce(gpui::Rgba) -> gpui::AnyElement>>,
|
||||
on_click: Option<Box<dyn Fn(&gpui::ClickEvent, &mut gpui::Window, &mut gpui::App)>>,
|
||||
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<AnyElement> = 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()
|
||||
|
||||
@@ -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<T>(icon: FontIcon, cx: &gpui::Context<T>) -> gpui::Svg {
|
||||
let theme = cx.global::<app::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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user