zng_wgt_material_icons/
lib.rs1#![doc(html_favicon_url = "https://zng-ui.github.io/res/zng-logo-icon.png")]
2#![doc(html_logo_url = "https://zng-ui.github.io/res/zng-logo.png")]
3#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
18#![warn(unused_extern_crates)]
19#![warn(missing_docs)]
20
21zng_wgt::enable_widget_macros!();
22
23#[cfg(all(
24 feature = "embedded",
25 any(feature = "outlined", feature = "filled", feature = "rounded", feature = "sharp")
26))]
27zng_env::on_process_start!(|args| {
28 if args.yield_until_app() {
29 return;
30 }
31 zng_app::APP.on_init(zng_app::hn!(|_| {
32 use zng_wgt::{ICONS, IconRequestArgs, prelude::UiNode, wgt_fn};
33 use zng_wgt_text::icon::{GlyphIcon, Icon};
34
35 let sets = [
38 #[cfg(feature = "outlined")]
39 (outlined::FONT_NAME, outlined::FONT_BYTES),
40 #[cfg(feature = "filled")]
41 (filled::FONT_NAME, filled::FONT_BYTES),
42 #[cfg(feature = "rounded")]
43 (rounded::FONT_NAME, rounded::FONT_BYTES),
44 #[cfg(feature = "sharp")]
45 (sharp::FONT_NAME, sharp::FONT_BYTES),
46 ];
47
48 for (name, bytes) in sets {
49 let font = zng_ext_font::CustomFont::from_bytes(name, zng_ext_font::FontBytes::from_static(bytes), 0);
50 zng_ext_font::FONTS.register(font);
51 }
52
53 ICONS.register(wgt_fn!(|args: IconRequestArgs| {
55 if let Some(strong_key) = args.name().strip_prefix("material/") {
56 #[expect(clippy::type_complexity)]
57 let sets: &[(&str, fn(&str) -> Option<GlyphIcon>)] = &[
58 #[cfg(feature = "outlined")]
59 ("outlined/", outlined::get),
60 #[cfg(feature = "filled")]
61 ("filled/", filled::get),
62 #[cfg(feature = "rounded")]
63 ("rounded/", rounded::get),
64 #[cfg(feature = "sharp")]
65 ("sharp/", sharp::get),
66 ];
67 for (name, get) in sets {
68 if let Some(key) = strong_key.strip_prefix(name)
69 && let Some(ico) = get(key)
70 {
71 return Icon!(ico);
72 }
73 }
74 }
75
76 UiNode::nil()
77 }));
78
79 ICONS.register_fallback(wgt_fn!(|args: IconRequestArgs| {
80 let sets = [
81 #[cfg(feature = "outlined")]
82 outlined::get,
83 #[cfg(feature = "filled")]
84 filled::get,
85 #[cfg(feature = "rounded")]
86 rounded::get,
87 #[cfg(feature = "sharp")]
88 sharp::get,
89 ];
90 for get in sets {
91 if let Some(ico) = get(args.name()) {
92 return Icon!(ico);
93 }
94 }
95 UiNode::nil()
96 }));
97 }));
98});
99
100#[cfg(any(feature = "outlined", feature = "filled", feature = "rounded", feature = "sharp"))]
101macro_rules! getters {
102 ($FONT_NAME:ident, $MAP:ident) => {
103 pub fn get(key: &str) -> Option<GlyphIcon> {
105 Some(GlyphIcon::new($FONT_NAME.clone(), *$MAP.get(key)?))
106 }
107
108 pub fn req(key: &str) -> GlyphIcon {
116 match get(key) {
117 Some(g) => g,
118 None => {
119 tracing::error!("icon {key:?} not found in `outlined`");
120 GlyphIcon::new("", '\0')
121 }
122 }
123 }
124
125 pub fn all() -> impl ExactSizeIterator<Item = (&'static str, GlyphIcon)> {
127 $MAP.entries()
128 .map(|(key, val)| (*key, GlyphIcon::new($FONT_NAME.clone(), *val)))
129 }
130 };
131}
132
133#[doc = include_str!(concat!(env!("OUT_DIR"), "/generated.outlined.docs.txt"))]
150#[cfg(feature = "outlined")]
151pub mod outlined {
152 use zng_ext_font::FontName;
153 use zng_wgt_text::icon::GlyphIcon;
154
155 pub const FONT_NAME: FontName = FontName::from_static("Material Icons Outlined");
157
158 #[cfg(feature = "embedded")]
160 pub const FONT_BYTES: &[u8] = include_bytes!("../fonts/MaterialIconsOutlined-Regular.otf");
161
162 include!(concat!(env!("OUT_DIR"), "/generated.outlined.map.rs"));
163 getters!(FONT_NAME, MAP);
164}
165
166#[doc = include_str!(concat!(env!("OUT_DIR"), "/generated.filled.docs.txt"))]
183#[cfg(feature = "filled")]
184pub mod filled {
185 use zng_ext_font::FontName;
186 use zng_wgt_text::icon::GlyphIcon;
187
188 pub const FONT_NAME: FontName = FontName::from_static("Material Icons");
190
191 #[cfg(feature = "embedded")]
193 pub const FONT_BYTES: &[u8] = include_bytes!("../fonts/MaterialIcons-Regular.ttf");
194
195 include!(concat!(env!("OUT_DIR"), "/generated.filled.map.rs"));
196 getters!(FONT_NAME, MAP);
197}
198
199#[doc = include_str!(concat!(env!("OUT_DIR"), "/generated.rounded.docs.txt"))]
216#[cfg(feature = "rounded")]
217pub mod rounded {
218 use zng_ext_font::FontName;
219 use zng_wgt_text::icon::GlyphIcon;
220
221 pub const FONT_NAME: FontName = FontName::from_static("Material Icons Rounded");
223
224 #[cfg(feature = "embedded")]
226 pub const FONT_BYTES: &[u8] = include_bytes!("../fonts/MaterialIconsRound-Regular.otf");
227
228 include!(concat!(env!("OUT_DIR"), "/generated.rounded.map.rs"));
229 getters!(FONT_NAME, MAP);
230}
231
232#[doc = include_str!(concat!(env!("OUT_DIR"), "/generated.sharp.docs.txt"))]
249#[cfg(feature = "sharp")]
250pub mod sharp {
251 use zng_ext_font::FontName;
252 use zng_wgt_text::icon::GlyphIcon;
253
254 pub const FONT_NAME: FontName = FontName::from_static("Material Icons Sharp");
256
257 #[cfg(feature = "embedded")]
259 pub const FONT_BYTES: &[u8] = include_bytes!("../fonts/MaterialIconsSharp-Regular.otf");
260
261 include!(concat!(env!("OUT_DIR"), "/generated.sharp.map.rs"));
262 getters!(FONT_NAME, MAP);
263}