Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions crates/moon-ui-components-assets/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# GPUI Component Assets
# Moon UI component assets

The default assets bundle for [GPUI Component](https://github.com/longbridge/gpui-component).
Bundled SVG icons for Moon UI components.

The Cargo package is `moon-ui-components-assets`. The Rust library name stays
`gpui_component_assets`, and the workspace depends on it as
`gpui-component-assets`. `moon-ui` re-exports `Assets` as `MoonAssets`.

`build.rs` publishes the absolute path of `assets/icons` through the Cargo
`links` key `gpui-component-default-icons`. `moon-ui-components` reads that
path as `DEP_GPUI_COMPONENT_DEFAULT_ICONS_ICONS_DIR` and generates `IconName`
from the SVG files in that directory.

On native targets, `Assets` embeds `assets/icons/**/*.svg` with RustEmbed and
implements `gpui::AssetSource`. It is a unit struct, so callers pass `Assets`
by value. `Assets::new` ignores its endpoint argument.

On `wasm32`, the icons are not embedded. `Assets::new` stores the endpoint.
`load` downloads a path only when it starts with `icons/` and ends with
`.svg`, using `reqwest` against `{endpoint}/assets/{path}`, and keeps the
bytes in memory. Until that download finishes, `load` returns an error. The
sprite atlas does not store the failure, so a later paint calls `load` again.

## License

Expand Down
24 changes: 15 additions & 9 deletions crates/moon-ui-components-assets/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
/// Embed application assets for GPUI Component.
/// Bundled SVG icons for Moon UI components.
///
/// This assets provides icons svg files for [IconName](https://docs.rs/gpui-component/latest/gpui_component/enum.IconName.html).
/// The Rust library name is `gpui_component_assets`. `moon-ui` re-exports
/// [`Assets`] as `MoonAssets`. `moon-ui-components` generates `IconName` from
/// `assets/icons` using the directory this crate's build script publishes.
///
/// ## Usage
///
/// Native builds pass the unit struct straight through:
///
/// ```rust,no_run
/// use gpui::*;
/// use gpui_component_assets::Assets;
///
/// let app = gpui_platform::application().with_assets(Assets);
/// ```
///
/// ## Platform Differences
/// ## Platform differences
///
/// - **Native (Desktop)**: Icons are embedded in the binary using RustEmbed
/// - **WASM (Web)**: Icons are downloaded from CDN using web_sys::Request
/// - This significantly reduces WASM bundle size
/// - Icons are downloaded on-demand when first used
/// - Downloaded icons are cached in memory
/// - **Native**: `assets/icons/**/*.svg` is embedded with RustEmbed.
/// [`Assets::new`] ignores its endpoint.
/// - **WASM**: icons are not embedded. [`Assets::new`] stores an endpoint, and
/// `load` fetches a path with `reqwest` from `{endpoint}/assets/{path}` only
/// when that path starts with `icons/` and ends with `.svg`. The bytes are
/// cached in memory. Until the download finishes, `load` returns an error.
/// The sprite atlas does not keep that failure, so a later paint calls
/// `load` again.
#[cfg(not(target_family = "wasm"))]
mod native_assets;

Expand Down
Loading