Skip to main content

Crate gpui_kit_sf_symbols

Crate gpui_kit_sf_symbols 

Source
Expand description

Apple SF Symbols for GPUI Kit.

SfSymbol plugs into GPUI Kit’s Icon through the IconNamed trait, and SfSymbolAssets serves the matching SVGs. Symbols are not bundled (Apple’s license does not allow it): they are rendered as vector paths from the running system, so they look exactly like the OS’s own, in any of the nine weights, and tint with the text color like every other GPUI icon.

use gpui_kit::*;
use gpui_kit::assets::Assets;
use gpui_kit::component::Icon;
use gpui_kit_sf_symbols::{SfSymbol, SfSymbolAssets, Weight};

const GEAR: SfSymbol = SfSymbol::from_static("gearshape");

struct Example;

impl Render for Example {
    fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
        div()
            .flex()
            .gap_2()
            .child(Icon::new(GEAR))                                     // regular
            .child(Icon::new(SfSymbol::new("heart.fill").bold()))
            .child(Icon::new(SfSymbol::new("wifi").variable_value(0.5)))
            .child(SfSymbol::new("folder.badge.plus").hierarchical())   // no `Icon` needed
    }
}

fn main() {
    // SF Symbols first, then GPUI Kit's own component icons.
    gpui_kit::application()
        .with_assets(SfSymbolAssets.with(Assets))
        .run(|cx| { /* ... */ });
}

§Platform support

Rendering needs macOS 13 or later. Elsewhere, or for a name the system does not know, a symbol simply draws nothing, the same as any other missing asset in GPUI; check is_available or SfSymbol::exists to choose a fallback icon. The crate builds on every platform.

Symbols are rendered with SwiftUI, which only runs on the main thread. GPUI loads icons there while painting, so this costs nothing in practice. Called from another thread, SfSymbol::svg waits for the main thread and gives up after a couple of seconds if it is busy. Each symbol is rendered once per style and cached.

Asset paths have the form sf-symbols/{style}/{name}.svg, e.g. sf-symbols/bold+hierarchical/folder.badge.plus.svg, so they never collide with GPUI Kit’s icons/… paths.

Structs§

Layered
Two asset sources layered together: load tries the first source, then the second; list merges both.
ParseError
Returned when parsing an unknown weight name.
SfSymbol
An SF Symbol by name, e.g. "gearshape" or "folder.badge.plus", with its weight, rendering mode and variable value.
SfSymbolAssets
Renders any sf-symbols/… path from the system.

Enums§

Rendering
How a symbol’s layers are drawn. Both come out in a single color, so the icon still follows the text color.
Weight
A symbol weight, matching the system font weights.

Constants§

PATH_PREFIX
Prefix shared by every asset path this crate serves.

Traits§

IconNamed
A named icon that resolves to a path in an application’s asset source. Implement this for custom icon sets accepted by GPUI Component’s Icon.

Functions§

is_available
Whether SF Symbols can be rendered here: macOS 13 or later.