- 统一多处函数参数和调用的换行风格,保持代码风格一致 - 规范多处模块导入顺序和空行,提升代码整洁度 - 优化结构体字段与函数定义的缩进和排版格式 - 调整组件创建和订阅事件代码格式,增强代码逻辑清晰度 - 统一代码块和表达式的换行方式,避免超长行 - 整理并规范导出相关类型和模块的声明顺序 - 修复部分换行和逗号位置,提高代码规范性 - 对部分闭包和事件处理函数的参数换行为多行,提升可读性
Icon assets in GPUI Component
The IconName is a enum that defined a bunch of icon names, because some internal components in GPUI Component will use them.
You can see, we have a lot of svg icon files in the assets/icons folder, but we are not embed all of the icon files in the library by default. This for keep the library size small.
So you must have your own icon files to use the Icon component in GPUI Component.
You can download the icon files from here or use your own icon files as you wish, just use the same filename as the icon name (match with the IconName defined) you want to use.
For example your assets folder:
app_root
assets
icons
close.svg
menu.svg
...
src
main.rs
Cargo.toml
You also can just copy the svg files you want from the assets/icons folder in GPUI Component repo to your own assets folder.
How to use
You need define a Assets struct with rust-embed to register assets to GPUI application.
use anyhow::anyhow;
use gpui::*;
use rust_embed::RustEmbed;
use std::borrow::Cow;
#[derive(RustEmbed)]
#[folder = "./assets"]
#[include = "icons/**/*.svg"]
pub struct Assets;
impl AssetSource for Assets {
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
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<Vec<SharedString>> {
Ok(Self::iter()
.filter_map(|p| p.starts_with(path).then(|| p.into()))
.collect())
}
}
fn main() {
// Call with_assets to register assets
let app = Application::new().with_assets(Assets);
// ...
}
Use default bundled assets.
The gpui-component-assets crate provide a default bundled assets implementation that include all the icon files in the assets/icons folder.
If you don't want to manage your own icon files, you can just use the default bundled assets.
Just add gpui-component-assets as a dependency in your Cargo.toml:
[dependencies]
gpui-component = "*"
gpui-component-assets = "*"
And then use it in your application:
let app = Application::new().with_assets(gpui_component_assets::Assets);