Module icon

Module icon 

Source
Expand description

Icons service, icon font widget and other types.

§Service

The ICONS service bridges icon providers and icon users. Icon theme providers can register handlers that provide a node that renders the icon identified by name. Widget styles or other UI only need to request the icon, avoiding having to embed icon resources in lib crates and avoiding icons having a fixed appearance.

use zng::{icon, prelude::*};

icon::ICONS.register(wgt_fn!(|a: icon::IconRequestArgs| {
    match a.name() {
        "accessibility" => Text!("A"),
        "settings" => Text!("S"),
        _ => UiNode::nil(),
    }
})); }

The example above registers a handler that provides two “icons” that are rendered by a Text! widgets.

§Widget

The Icon! widget renders icons using an icon font, it allows setting the font and icon in a single value and can auto size the font size, this makes it a better alternative to just using the Text! widget.

use zng::{icon, prelude::*};

icon::Icon! {
    ico = icon::material::rounded::req("accessibility");
    ico_size = 80;
}

You can implement your own icon sets by providing GlyphIcon instances or a type that converts to GlyphIcon. Glyph icons define a font name and a GlyphSource that can be a char or a ligature text.

use zng::{font, icon, prelude::*};

let font = font::CustomFont::from_file("Font Awesome 6 Free-Regular", r#"Font Awesome 6 Free-Regular-400.otf"#, 0);
font::FONTS.register(font).wait_rsp().await.unwrap();

icon::Icon! {
    ico = icon::GlyphIcon::new("Font Awesome 6 Free-Regular", "address-book").with_ligatures();
    ico_size = 80;
}

The example above loads an icon font and display one of the icons selected using a ligature that matches "address-book".

§Full API

See zng_wgt_text::icon for the full widget API.

Modules§

material
Material Icons

Structs§

GlyphIcon
Represents an icon glyph and font.
ICONS
Service that provides icon drawing widgets.
Icon
W Render icons defined as glyphs in an icon font.
IconRequestArgs
Arguments for ICONS.register.

Enums§

GlyphSource
Identifies an icon glyph in the font set.

Traits§

CommandIconExt
Adds the icon command metadata.

Functions§

ico_color
P Sets the icon font color.
ico_size
P Sets the icon font size.