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§
- Glyph
Icon - Represents an icon glyph and font.
- ICONS
- Service that provides icon drawing widgets.
- Icon
WRender icons defined as glyphs in an icon font.- Icon
Request Args - Arguments for
ICONS.register.
Enums§
- Glyph
Source - Identifies an icon glyph in the font set.
Traits§
- Command
Icon Ext - Adds the
iconcommand metadata.