Files
novem/src/component/font_icon.rs

74 lines
1.6 KiB
Rust

use gpui::{Refineable as _, RenderOnce, Styled, svg};
use paste::paste;
use crate::app;
macro_rules! define_font_icons {
($($name:ident),+ $(,)?) => {
paste! {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum FontIcon {
$($name),+
}
pub const fn icon_path(icon: FontIcon) -> &'static str {
match icon {
$(
FontIcon::$name => concat!(
"asset/font_icon/",
stringify!([<$name:snake>]),
".svg"
),
)+
}
}
}
};
}
define_font_icons!(
Check,
ChevronDown,
FolderGit,
Github,
ArrowRight,
Cat,
PencilLine,
UserPlus,
List,
PullRequestArrow,
PullRequestClosed,
PullRequestDraft
);
#[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
}
}