-
Notifications
You must be signed in to change notification settings - Fork 9
Component Icon
Renders an icon from embedded assets (built-in IconNames) or from an
external path string (your own SVG shipped via your AssetSource).
The icon(...) constructor accepts anything that converts into
IconPath:
-
IconPath::Embeded(IconName)— the 13 universal icons shipped insideyororen-ui-core. -
IconPath::External(SharedString)— any path yourAssetSourcecan load (e.g."icons/brand-logo.svg").
v0.3: The 5 app-specific
IconNamevariants from v0.2 (Microsoft,Minecraft,Modpack,Server,PingIndicator(usize)) were removed. They are now loaded withIconPath::External(...). SeeMIGRATION.md.
use gpui::px;
use yororen_ui::component::{icon, IconName};
let view = icon(IconName::Search).size(px(16.));use gpui::px;
use yororen_ui::component::{icon, IconPath};
let view = icon(IconPath::External("icons/microsoft.svg".into())).size(px(16.));
// Or — `&'static str` / `String` / `SharedString` convert implicitly:
let view = icon("icons/your-icon.svg").size(px(16.));The path is resolved through your gpui::AssetSource. The simplest
setup is to ship the SVG alongside your app and combine it with
UiAsset via CompositeAssetSource:
use gpui::Application;
use yororen_ui::assets::{CompositeAssetSource, UiAsset};
struct MyAppAssets;
impl gpui::AssetSource for MyAppAssets { /* load("icons/...") */ }
let app = Application::new()
.with_assets(CompositeAssetSource::new(MyAppAssets, UiAsset));- Inline icons in buttons, labels, menus
- Decoration and status markers
-
icon(impl Into<IconPath>): constructor. Accepts anIconName, anIconPath, a&'static str, aString, or aSharedString. -
.size(px(...)): icon size (default:tokens.sizes.icon_md, currently14px). -
.color(Hsla): explicit color -
.inherit_color(bool): whentrue, do not set a default color (use parent text color) -
.id(...)/.key(...): stable element id
These resolve to assets/icons/*.svg files inside yororen-ui-core:
IconName |
SVG path (relative to asset root) |
|---|---|
IconName::Search |
icons/search.svg |
IconName::Arrow(Up) |
icons/arrow-up.svg |
IconName::Arrow(Down) |
icons/arrow-down.svg |
IconName::Arrow(Left) |
icons/arrow-left.svg |
IconName::Arrow(Right) |
icons/arrow-right.svg |
IconName::Check |
icons/check.svg |
IconName::Warning |
icons/warning.svg |
IconName::Info |
icons/info.svg |
IconName::Close |
icons/close.svg |
IconName::Maximize(true) |
icons/maximize-on.svg |
IconName::Maximize(false) |
icons/maximize-off.svg |
IconName::Minimize |
icons/minimize.svg |
IconName::User |
icons/user.svg |
IconName::Pencil |
icons/pencil.svg |
IconName::Trash |
icons/trash.svg |
IconName::File |
icons/file.svg |
IconName::Folder |
icons/folder.svg |
The core asset folder also contains a few extra SVGs that aren't
exposed through IconName (window controls, progress indicators, …).
Reference them via IconPath::External("icons/window-close.svg") etc.
- Size:
tokens.sizes.icon_md(14pxby default). Override per-call with.size(px(...))or change the default for the whole app by settingtheme.tokens.sizes.icon_mdin your custom theme. - Color:
- if
.color(...)is set: use that - else if
.inherit_color(true): leave color unspecified (inherit from parent) - otherwise: use
theme.content.primary
- if
- If neither
.color(...)nor.inherit_color(true)is set, Icon usestheme.content.primary. - Built-in icons require that you provide Yororen UI assets at app startup.
See
Guide-Quick-Start(assets section). - The
Embededvariant name is intentionally retained (with the spelling used by the source) for backwards source compatibility; new code can ignore the spelling quirk and just pass anIconNametoicon(...).
use gpui::px;
use yororen_ui::component::{icon, text, IconName};
let view = text("Info")
.text_color(gpui::rgb(0xFF0000).into())
.with_icon(icon(IconName::Info).size(px(14.)).inherit_color(true));Yororen UI v0.3.0 · repository · Apache-2.0 · This wiki documents Yororen UI v0.3.0.
This wiki documents Yororen UI v0.3.0 — the headless-core, swappable-renderer build.