1use iced::advanced::graphics::text::font_system;
8use iced::font::{Family, Weight};
9use iced::widget::text;
10use iced::{Element, Font};
11use std::borrow::Cow;
12use std::fmt;
13
14pub fn load_font_fontawesome_ttf() {
59 let mut font_system = font_system().write().unwrap();
60 font_system.load_font(Cow::from(FONT_DATA_FA_REGULAR_TTF));
61 font_system.load_font(Cow::from(FONT_DATA_FA_BRANDS_TTF));
62 font_system.load_font(Cow::from(FONT_DATA_FA_SOLID_TTF));
63}
64
65pub fn load_font_fontawesome_otf() {
69 let mut font_system = font_system().write().unwrap();
70 font_system.load_font(Cow::from(FONT_DATA_FA_REGULAR_TTF));
71 font_system.load_font(Cow::from(FONT_DATA_FA_BRANDS_TTF));
72 font_system.load_font(Cow::from(FONT_DATA_FA_SOLID_TTF));
73}
74
75pub fn iced_text_icon_regular<'a, Message>(code: &str, size: u16) -> Element<'a, Message> {
81 let code_u32 = u32::from_str_radix(&code, 16).unwrap();
82 let unicode_char = char::from_u32(code_u32).unwrap();
83 text(unicode_char).font(FONT_FA_REGULAR).size(size).into()
84}
85
86pub fn iced_text_icon_solid<'a, Message>(code: &str, size: u16) -> Element<'a, Message> {
92 let code_u32 = u32::from_str_radix(&code, 16).unwrap();
93 let unicode_char = char::from_u32(code_u32).unwrap();
94 text(unicode_char).font(FONT_FA_SOLID).size(size).into()
95}
96
97pub const FONT_FA_REGULAR: Font = Font {
101 family: Family::Name("Font Awesome 6 Free"),
102 ..Font::DEFAULT
103};
104
105pub const FONT_FA_SOLID: Font = Font {
114 family: Family::Name("Font Awesome 6 Free"),
115 weight: Weight::Black, ..Font::DEFAULT
117};
118
119pub const FONT_DATA_FA_REGULAR_OTF: &[u8] =
124 include_bytes!("../fonts/font-awesome-6-free-regular-400.otf");
125
126pub const FONT_DATA_FA_BRANDS_OTF: &[u8] =
127 include_bytes!("../fonts/font-awesome-6-brands-regular-400.otf");
128
129pub const FONT_DATA_FA_SOLID_OTF: &[u8] =
130 include_bytes!("../fonts/font-awesome-6-free-solid-900.otf");
131
132pub const FONT_DATA_FA_REGULAR_TTF: &[u8] = include_bytes!("../fonts/fa-regular-400.ttf");
133
134pub const FONT_DATA_FA_BRANDS_TTF: &[u8] = include_bytes!("../fonts/fa-brands-400.ttf");
135
136pub const FONT_DATA_FA_SOLID_TTF: &[u8] = include_bytes!("../fonts/fa-solid-900.ttf");
137
138pub const FA_ICON_USER: &str = "f007";
144
145pub const FA_ICON_NEW: &str = "f15b";
147
148pub const FA_ICON_OPEN: &str = "f07c";
150
151pub const FA_ICON_SAVE: &str = "f0c7";
153
154pub const FA_ICON_0: &str = "30";
160
161pub const FA_ICON_1: &str = "31";
163
164pub const FA_ICON_2: &str = "32";
166
167pub const FA_ICON_3: &str = "33";
169
170pub const FA_ICON_4: &str = "34";
172
173pub const FA_ICON_5: &str = "35";
175
176pub const FA_ICON_6: &str = "36";
178
179pub const FA_ICON_7: &str = "37";
181
182pub const FA_ICON_8: &str = "38";
184
185pub const FA_ICON_9: &str = "39";
187
188pub const FA_ICON_CIRCLE_CHECK: &str = "f058";
194
195pub const FA_ICON_CIRCLE_XMARK: &str = "f057";
197
198pub const FA_ICON_BARS: &str = "f0c9";
204
205pub const FA_ICON_GEAR: &str = "f013";
209
210pub const FA_ICON_SCREWDRIVER_WRENCH: &str = "f7d9";
214
215pub const FA_ICON_ID_CARD: &str = "f2c2";
221
222pub const FA_ICON_ID_CARD_CLIP: &str = "f47f";
224
225pub const FA_ICON_ID_BADGE: &str = "f2c1";
227
228#[derive(Debug, Clone, Copy, PartialEq, Eq)]
236pub enum FaIcon {
237 User,
238 CircleCheck,
239 CircleXmark,
240 ScrewdriverWrench,
241 Gear,
242 Bars,
243 New,
244 Open,
245 Save,
246 Number0,
247 Number1,
248 Number2,
249 Number3,
250 Number4,
251 Number5,
252 Number6,
253 Number7,
254 Number8,
255 Number9,
256 IdCard,
257 IdCardClip,
258 IdBadge,
259}
260
261impl fmt::Display for FaIcon {
262 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
263 f.write_str(self.as_str())
264 }
265}
266
267impl FaIcon {
268 pub fn as_str(&self) -> &str {
269 match self {
270 FaIcon::User => "f007",
271 FaIcon::CircleCheck => "f058",
272 FaIcon::CircleXmark => "f057",
273 FaIcon::ScrewdriverWrench => "f7d9",
274 FaIcon::Gear => "f013",
275 FaIcon::Bars => "f0c9",
276 FaIcon::New => "f15b",
277 FaIcon::Open => "f07c",
278 FaIcon::Save => "f0c7",
279 FaIcon::Number0 => "30",
280 FaIcon::Number1 => "31",
281 FaIcon::Number2 => "32",
282 FaIcon::Number3 => "33",
283 FaIcon::Number4 => "34",
284 FaIcon::Number5 => "35",
285 FaIcon::Number6 => "36",
286 FaIcon::Number7 => "37",
287 FaIcon::Number8 => "38",
288 FaIcon::Number9 => "39",
289 FaIcon::IdCard => "f2c2",
290 FaIcon::IdCardClip => "f47f",
291 FaIcon::IdBadge => "f2c1",
292 }
293 }
294}