2023-10-04 08:51:47 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
|
|
use anyhow::{anyhow, Result};
|
2023-11-06 18:46:10 +00:00
|
|
|
use gpui::{AssetSource, SharedString};
|
2023-10-04 08:51:47 +00:00
|
|
|
use rust_embed::RustEmbed;
|
|
|
|
|
|
|
|
#[derive(RustEmbed)]
|
|
|
|
#[folder = "../../assets"]
|
|
|
|
#[include = "fonts/**/*"]
|
|
|
|
#[include = "icons/**/*"]
|
add `ui::Vector` and separate images from icons (#17815)
This PR pulls non-icon assets out of `ui::components::icon` in
preparation for icon standardization.
In the future icons will have standard names and sizes, and these image
assets won't conform to those constraints.
We can also add a `ui::components::image::Image` wrapper around the
`gpui::img` element in the future for any Zed-specific image styling we
want to enforce.
Of note:
```rust
#[derive(Debug, PartialEq, Eq, Copy, Clone, EnumIter, EnumString, IntoStaticStr, Serialize, Deserialize, DerivePathStr)]
#[strum(serialize_all = "snake_case")]
#[path_str(prefix = "images", suffix = ".svg")]
pub enum VectorName {
ZedLogo,
ZedXCopilot,
}
```
You can see in the above code we no longer need to manually specify
paths for image/icon enums like we currently do in
`ui::components::icon`.
The icon component will get this same treatment in the future, once we:
- do the design work needed to standardize the icons
- remove unused icons
- update icon names
Release Notes:
- N/A
2024-09-13 21:44:16 +00:00
|
|
|
#[include = "images/**/*"]
|
2023-10-04 08:51:47 +00:00
|
|
|
#[include = "themes/**/*"]
|
|
|
|
#[include = "sounds/**/*"]
|
|
|
|
#[include = "*.md"]
|
|
|
|
#[exclude = "*.DS_Store"]
|
|
|
|
pub struct Assets;
|
|
|
|
|
|
|
|
impl AssetSource for Assets {
|
2024-05-30 01:06:45 +00:00
|
|
|
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
|
2023-10-24 15:47:41 +00:00
|
|
|
Self::get(path)
|
2023-10-04 08:51:47 +00:00
|
|
|
.map(|f| f.data)
|
|
|
|
.ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
|
2024-09-06 09:58:39 +00:00
|
|
|
.map(Some)
|
2023-10-04 08:51:47 +00:00
|
|
|
}
|
|
|
|
|
2023-10-24 15:47:41 +00:00
|
|
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
2023-10-04 08:51:47 +00:00
|
|
|
Ok(Self::iter()
|
2023-10-24 15:47:41 +00:00
|
|
|
.filter(|p| p.starts_with(path))
|
2023-10-04 08:51:47 +00:00
|
|
|
.map(SharedString::from)
|
|
|
|
.collect())
|
|
|
|
}
|
|
|
|
}
|