1use std::borrow::Cow;
8use iced::advanced::graphics::text::font_system;
9use iced::{Element, Font};
10use iced::font::{Family, Weight};
11use iced::widget::text;
12use std::fmt;
13
14
15pub fn load_font_fontawesome_ttf() {
62 let mut font_system = font_system().write().unwrap();
63 font_system.load_font(Cow::from(FONT_DATA_FA_REGULAR_TTF));
64 font_system.load_font(Cow::from(FONT_DATA_FA_BRANDS_TTF));
65 font_system.load_font(Cow::from(FONT_DATA_FA_SOLID_TTF));
66}
67
68pub fn load_font_fontawesome_otf() {
72 let mut font_system = font_system().write().unwrap();
73 font_system.load_font(Cow::from(FONT_DATA_FA_REGULAR_TTF));
74 font_system.load_font(Cow::from(FONT_DATA_FA_BRANDS_TTF));
75 font_system.load_font(Cow::from(FONT_DATA_FA_SOLID_TTF));
76}
77
78pub fn iced_text_icon_regular<'a, Message>(code: &str, size: u16) -> Element<'a, Message> {
84 let code_u32 = u32::from_str_radix(&code, 16).unwrap();
85 let unicode_char = char::from_u32(code_u32).unwrap();
86 text(unicode_char).font(FONT_FA_REGULAR).size(size).into()
87}
88
89pub fn iced_text_icon_solid<'a, Message>(code: &str, size: u16) -> Element<'a, Message> {
95 let code_u32 = u32::from_str_radix(&code, 16).unwrap();
96 let unicode_char = char::from_u32(code_u32).unwrap();
97 text(unicode_char).font(FONT_FA_SOLID).size(size).into()
98}
99
100pub const FONT_FA_REGULAR: Font = Font {
104 family: Family::Name("Font Awesome 6 Free"),
105 ..Font::DEFAULT
106};
107
108pub const FONT_FA_SOLID: Font = Font {
117 family: Family::Name("Font Awesome 6 Free"),
118 weight: Weight::Black, ..Font::DEFAULT
120};
121
122pub const FONT_DATA_FA_REGULAR_OTF: &[u8] =
127 include_bytes!("../fonts/font-awesome-6-free-regular-400.otf");
128
129pub const FONT_DATA_FA_BRANDS_OTF: &[u8] =
130 include_bytes!("../fonts/font-awesome-6-brands-regular-400.otf");
131
132pub const FONT_DATA_FA_SOLID_OTF: &[u8] =
133 include_bytes!("../fonts/font-awesome-6-free-solid-900.otf");
134
135pub const FONT_DATA_FA_REGULAR_TTF: &[u8] =
136 include_bytes!("../fonts/fa-regular-400.ttf");
137
138pub const FONT_DATA_FA_BRANDS_TTF: &[u8] =
139 include_bytes!("../fonts/fa-brands-400.ttf");
140
141pub const FONT_DATA_FA_SOLID_TTF: &[u8] =
142 include_bytes!("../fonts/fa-solid-900.ttf");
143
144pub const FA_ICON_USER: &str = "f007";
150
151pub const FA_ICON_NEW: &str = "f15b";
153
154pub const FA_ICON_OPEN: &str = "f07c";
156
157pub const FA_ICON_SAVE: &str = "f0c7";
159
160pub const FA_ICON_0: &str = "30";
166
167pub const FA_ICON_1: &str = "31";
169
170pub const FA_ICON_2: &str = "32";
172
173pub const FA_ICON_3: &str = "33";
175
176pub const FA_ICON_4: &str = "34";
178
179pub const FA_ICON_5: &str = "35";
181
182pub const FA_ICON_6: &str = "36";
184
185pub const FA_ICON_7: &str = "37";
187
188pub const FA_ICON_8: &str = "38";
190
191pub const FA_ICON_9: &str = "39";
193
194pub const FA_ICON_CIRCLE_CHECK: &str = "f058";
200
201pub const FA_ICON_CIRCLE_XMARK: &str = "f057";
203
204pub const FA_ICON_BARS: &str = "f0c9";
210
211pub const FA_ICON_GEAR: &str = "f013";
215
216pub const FA_ICON_SCREWDRIVER_WRENCH: &str = "f7d9";
220
221
222#[derive(Debug, Clone, Copy, PartialEq, Eq)]
226pub enum FaIcon {
227 User,
228 CircleCheck,
229 CircleXmark,
230 ScrewdriverWrench,
231 Gear,
232 Bars,
233 New,
234 Open,
235 Save,
236 Number0,
237 Number1,
238 Number2,
239 Number3,
240 Number4,
241 Number5,
242 Number6,
243 Number7,
244 Number8,
245 Number9,
246}
247
248impl fmt::Display for FaIcon {
249 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
250 f.write_str(self.as_str())
251 }
252}
253
254impl FaIcon {
255 pub fn as_str(&self) -> &str {
256 match self {
257 FaIcon::User => "f007",
258 FaIcon::CircleCheck => "f058",
259 FaIcon::CircleXmark => "f057",
260 FaIcon::ScrewdriverWrench => "f7d9",
261 FaIcon::Gear => "f013",
262 FaIcon::Bars => "f0c9",
263 FaIcon::New => "f15b",
264 FaIcon::Open => "f07c",
265 FaIcon::Save => "f0c7",
266 FaIcon::Number0 => "30",
267 FaIcon::Number1 => "31",
268 FaIcon::Number2 => "32",
269 FaIcon::Number3 => "33",
270 FaIcon::Number4 => "34",
271 FaIcon::Number5 => "35",
272 FaIcon::Number6 => "36",
273 FaIcon::Number7 => "37",
274 FaIcon::Number8 => "38",
275 FaIcon::Number9 => "39",
276 }
277 }
278}