Skip to main content

gpui_cn/composer/
icons.rs

1use std::borrow::Cow;
2
3use gpui_kit::{AssetSource, Result, SharedString, assets::Assets};
4
5gpui_kit::assets::icon_assets!(
6    ComposerExtras,
7    [
8        ClipboardList,
9        FileCode,
10        FileSpreadsheet,
11        Gauge,
12        GitBranch,
13        Hand,
14        Image,
15        Laptop,
16        Lock,
17        LockOpen,
18        Mic,
19        Presentation,
20        ShieldAlert,
21        ShieldCheck,
22        Video,
23    ]
24);
25
26/// An asset source for an application that uses the composer family: the
27/// default `gpui_kit::assets::Assets` plus the Lucide icons the composer's
28/// defaults draw, which the default set does not hold (the microphone, the
29/// shield, the file kinds, and the git branch).
30///
31/// An application that does not register it still works: it passes its own
32/// icons to the components that take one, and a default icon that is not
33/// registered renders nothing.
34///
35/// ```no_run
36/// let app = gpui_kit::application().with_assets(gpui_cn::ComposerAssets);
37/// ```
38#[derive(Clone, Copy, Debug, Default)]
39pub struct ComposerAssets;
40
41impl AssetSource for ComposerAssets {
42    fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
43        if let Some(bytes) = ComposerExtras.load(path)? {
44            return Ok(Some(bytes));
45        }
46        Assets.load(path)
47    }
48
49    fn list(&self, path: &str) -> Result<Vec<SharedString>> {
50        let mut paths = Assets.list(path)?;
51        paths.extend(ComposerExtras.list(path)?);
52        paths.sort();
53        paths.dedup();
54        Ok(paths)
55    }
56}