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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amit VermaandClaude Opus 5.5 authored and 雷电芽衣 committed 2026-10-04 17:24:39 -04:00
1 parent 2f02c82c6a
commit 2fb505ee98
9 files changed
+145 -17

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
use std::borrow::Cow;
use ely_gpui_component::Assets;
use gpui::{AssetSource, SharedString};
pub const CUSTOM_ICON: &str = "app-icons/mark.svg";
pub struct GalleryAssets;
impl AssetSource for GalleryAssets {
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)
}
}
+3 -2
View File
@@ -20,6 +20,7 @@ macro_rules! asset {
};
}
mod assets;
#[cfg(not(target_family = "wasm"))]
mod capture;
mod pages;
@@ -42,7 +43,7 @@ use std::path::PathBuf;
#[cfg(not(target_family = "wasm"))]
use anyhow::{Context as _, Result, bail};
#[cfg(not(target_family = "wasm"))]
use ely_gpui_component::Assets;
use assets::GalleryAssets;
use ely_gpui_component::theme::{Mode, Theme};
use gpui::{
App, AppContext, Bounds, KeyBinding, Menu, MenuItem, SharedString, TitlebarOptions,
@@ -201,7 +202,7 @@ fn main() -> Result<()> {
// A script aims across its page; stories hold part.
let scripted = start.narrow.is_none() && start.story.is_none();
gpui_platform::application()
.with_assets(Assets)
.with_assets(GalleryAssets)
.run(move |cx: &mut App| {
let window = launch(start, cx);
if let Some(dir) = capture {
+11 -1
View File
@@ -14,6 +14,7 @@ use gpui::{
};
use crate::{
assets::CUSTOM_ICON,
probe::probe,
ui::{UNREAD, blocked, code, picture, row, section, specimen, specimens},
};
@@ -44,7 +45,7 @@ pub fn icon(cx: &App) -> impl IntoElement + use<> {
];
section(
"Icon",
"Lucide, drawn as a mask. Color comes from the theme.",
"Bundled Lucide or an application's SVG asset, drawn as a themed mask.",
cx,
)
.child(specimens().children(
@@ -55,6 +56,15 @@ pub fn icon(cx: &App) -> impl IntoElement + use<> {
specimen(name, Icon::new(IconName::CircleCheck).color(color), cx)
})),
)
.child(
specimens().child(specimen(
"custom SVG",
Icon::from_path(CUSTOM_ICON)
.size(IconSize::Xl)
.color(colors.accent),
cx,
)),
)
}
pub fn icon_set(cx: &App) -> impl IntoElement + use<> {
+4 -3
View File
@@ -6,14 +6,15 @@ use std::{
};
use anyhow::{Context as _, Result, anyhow, bail};
use ely_gpui_component::Assets;
use gpui::{Application, AsyncApp, SharedString, WindowHandle};
use gpui_web::{CanvasFontFallback, WebBackendPreference, WebPlatform};
use wasm_bindgen::prelude::*;
use web_sys::UrlSearchParams;
use crate::{
Start, choose, launch, pages,
Start,
assets::GalleryAssets,
choose, launch, pages,
shell::{Choice, Gallery},
};
@@ -97,7 +98,7 @@ pub fn start() {
let http = Arc::new(platform.fetch_http_client());
Application::with_platform(platform)
.with_http_client(http)
.with_assets(Assets)
.with_assets(GalleryAssets)
.run(move |cx| {
cx.text_system()
.add_fonts(vec![Cow::Borrowed(HEBREW)])