Primitives · Icon::from_path draws an application's SVG with the theme's size and color; a path the asset source lacks fails at render
This commit is contained in:
1 parent
9977785de6
commit
dfe1e9f42c
9 files changed
+145
-17
No files matched your search
+31
-5
@@ -1,4 +1,4 @@
|
||||
use std::f32::consts::FRAC_PI_4;
|
||||
use std::{borrow::Cow, f32::consts::FRAC_PI_4};
|
||||
|
||||
use ely_gpui_component::{
|
||||
Assets,
|
||||
@@ -7,10 +7,31 @@ use ely_gpui_component::{
|
||||
theme::{ActiveTheme, IconSize},
|
||||
};
|
||||
use gpui::{
|
||||
App, AppContext, Context, FocusHandle, IntoElement, ParentElement, Radians, Render, Styled,
|
||||
Window, WindowOptions, div,
|
||||
App, AppContext, AssetSource, Context, FocusHandle, IntoElement, ParentElement, Radians,
|
||||
Render, SharedString, Styled, Window, WindowOptions, div,
|
||||
};
|
||||
|
||||
const CUSTOM_ICON: &str = "app-icons/mark.svg";
|
||||
|
||||
struct AppAssets;
|
||||
|
||||
impl AssetSource for AppAssets {
|
||||
fn load(&self, path: &str) -> gpui::Result<Option<Cow<'static, [u8]>>> {
|
||||
if path == CUSTOM_ICON {
|
||||
return Ok(Some(Cow::Borrowed(include_bytes!("../assets/mark.svg"))));
|
||||
}
|
||||
Assets.load(path)
|
||||
}
|
||||
|
||||
fn list(&self, path: &str) -> gpui::Result<Vec<SharedString>> {
|
||||
let mut assets = Assets.list(path)?;
|
||||
if CUSTOM_ICON.starts_with(path) {
|
||||
assets.push(CUSTOM_ICON.into());
|
||||
}
|
||||
Ok(assets)
|
||||
}
|
||||
}
|
||||
|
||||
struct Icons {
|
||||
focus: FocusHandle,
|
||||
}
|
||||
@@ -43,7 +64,12 @@ impl Render for Icons {
|
||||
.child(Icon::new(IconName::Check))
|
||||
.child(Icon::new(IconName::Rocket).size(IconSize::Xl))
|
||||
.child(Icon::new(IconName::CircleCheck).color(theme.colors.success))
|
||||
.child(Icon::new(IconName::Package).rotate(Radians(FRAC_PI_4))),
|
||||
.child(Icon::new(IconName::Package).rotate(Radians(FRAC_PI_4)))
|
||||
.child(
|
||||
Icon::from_path(CUSTOM_ICON)
|
||||
.size(IconSize::Xl)
|
||||
.color(theme.colors.accent),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
@@ -59,7 +85,7 @@ impl Render for Icons {
|
||||
|
||||
fn main() {
|
||||
gpui_platform::application()
|
||||
.with_assets(Assets)
|
||||
.with_assets(AppAssets)
|
||||
.run(|cx: &mut App| {
|
||||
ely_gpui_component::init(cx);
|
||||
IconTheme::default()
|
||||
|
||||
Reference in new issue
Block a user