Skip to main content

glassy_ui/
assets.rs

1use std::borrow::Cow;
2
3use gpui::{App, AssetSource, Result, SharedString};
4
5/// Bundled icons and Inter.
6pub struct Assets;
7
8impl AssetSource for Assets {
9    fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
10        let bytes: Option<&'static [u8]> = match path {
11            "icons/plus.svg" => Some(include_bytes!("../assets/icons/plus.svg")),
12            "icons/download.svg" => Some(include_bytes!("../assets/icons/download.svg")),
13            "icons/chevron-right.svg" => Some(include_bytes!("../assets/icons/chevron-right.svg")),
14            "icons/chevron-down.svg" => Some(include_bytes!("../assets/icons/chevron-down.svg")),
15            "icons/search.svg" => Some(include_bytes!("../assets/icons/search.svg")),
16            "icons/spinner.svg" => Some(include_bytes!("../assets/icons/spinner.svg")),
17            "icons/check.svg" => Some(include_bytes!("../assets/icons/check.svg")),
18            "fonts/InterVariable.ttf" => Some(include_bytes!("../assets/fonts/InterVariable.ttf")),
19            _ => None,
20        };
21        Ok(bytes.map(Cow::Borrowed))
22    }
23
24    fn list(&self, path: &str) -> Result<Vec<SharedString>> {
25        let all = [
26            "icons/plus.svg",
27            "icons/download.svg",
28            "icons/chevron-right.svg",
29            "icons/chevron-down.svg",
30            "icons/search.svg",
31            "icons/spinner.svg",
32            "icons/check.svg",
33            "fonts/InterVariable.ttf",
34        ];
35        Ok(all
36            .into_iter()
37            .filter(|p| p.starts_with(path))
38            .map(SharedString::from)
39            .collect())
40    }
41}
42
43/// Register the bundled Inter variable face. Call once at startup.
44pub fn load_fonts(cx: &App) -> gpui::Result<()> {
45    cx.text_system().add_fonts(vec![Cow::Borrowed(
46        include_bytes!("../assets/fonts/InterVariable.ttf").as_slice(),
47    )])
48}