From b740123d4beb9a0172beb90ea72d2f4c255c469e Mon Sep 17 00:00:00 2001 From: Iain Date: Fri, 24 Oct 2025 13:30:27 +0800 Subject: [PATCH] example: Add missed control icon assets (#1424) --- Cargo.lock | 1 + examples/window_title/Cargo.toml | 1 + .../assets/icons/window-close.svg | 9 ++++++ .../assets/icons/window-maximize.svg | 9 ++++++ .../assets/icons/window-minimize.svg | 9 ++++++ .../assets/icons/window-restore.svg | 10 +++++++ examples/window_title/src/main.rs | 28 ++++++++++++++++++- 7 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 examples/window_title/assets/icons/window-close.svg create mode 100644 examples/window_title/assets/icons/window-maximize.svg create mode 100644 examples/window_title/assets/icons/window-minimize.svg create mode 100644 examples/window_title/assets/icons/window-restore.svg diff --git a/Cargo.lock b/Cargo.lock index 9b0cee1f..69773b0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8804,6 +8804,7 @@ dependencies = [ "anyhow", "gpui", "gpui-component", + "rust-embed", ] [[package]] diff --git a/examples/window_title/Cargo.toml b/examples/window_title/Cargo.toml index a2bacdbe..1bfc0ada 100644 --- a/examples/window_title/Cargo.toml +++ b/examples/window_title/Cargo.toml @@ -9,6 +9,7 @@ version = "0.3.0" anyhow.workspace = true gpui.workspace = true gpui-component = { workspace = true } +rust-embed = { version = "8", features = ["interpolate-folder-path"] } [lints] workspace = true diff --git a/examples/window_title/assets/icons/window-close.svg b/examples/window_title/assets/icons/window-close.svg new file mode 100644 index 00000000..62b6b0c7 --- /dev/null +++ b/examples/window_title/assets/icons/window-close.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/examples/window_title/assets/icons/window-maximize.svg b/examples/window_title/assets/icons/window-maximize.svg new file mode 100644 index 00000000..9da4cd7e --- /dev/null +++ b/examples/window_title/assets/icons/window-maximize.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/examples/window_title/assets/icons/window-minimize.svg b/examples/window_title/assets/icons/window-minimize.svg new file mode 100644 index 00000000..708e27be --- /dev/null +++ b/examples/window_title/assets/icons/window-minimize.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/examples/window_title/assets/icons/window-restore.svg b/examples/window_title/assets/icons/window-restore.svg new file mode 100644 index 00000000..896b6b60 --- /dev/null +++ b/examples/window_title/assets/icons/window-restore.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/examples/window_title/src/main.rs b/examples/window_title/src/main.rs index 6e9c79b4..c3fe14b6 100644 --- a/examples/window_title/src/main.rs +++ b/examples/window_title/src/main.rs @@ -1,8 +1,34 @@ +use anyhow::anyhow; use gpui::*; use gpui_component::{ button::{Button, ButtonVariants}, v_flex, Root, TitleBar, }; +use rust_embed::Embed; +use std::borrow::Cow; + +#[derive(Embed)] +#[folder = "./assets"] +#[include = "icons/**/*.svg"] +pub struct Assets; + +impl AssetSource for Assets { + fn load(&self, path: &str) -> Result>> { + if path.is_empty() { + return Ok(None); + } + + Self::get(path) + .map(|f| Some(f.data)) + .ok_or_else(|| anyhow!("could not find asset at path \"{path}\"")) + } + + fn list(&self, path: &str) -> Result> { + Ok(Self::iter() + .filter_map(|p| p.starts_with(path).then(|| p.into())) + .collect()) + } +} pub struct Example; impl Render for Example { @@ -36,7 +62,7 @@ impl Render for Example { } fn main() { - let app = Application::new(); + let app = Application::new().with_assets(Assets); app.run(move |cx| { gpui_component::init(cx);