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() {
19 let mut font_system = font_system().write().unwrap();
20 font_system.load_font(Cow::from(FONT_DATA_FA_REGULAR));
21 font_system.load_font(Cow::from(FONT_DATA_FA_BRANDS));
22 font_system.load_font(Cow::from(FONT_DATA_FA_SOLID));
23}
24
25pub fn iced_text_icon_regular<'a, Message>(code: &str) -> Element<'a, Message> {
31 let code_u32 = u32::from_str_radix(&code, 16).unwrap();
32 let unicode_char = char::from_u32(code_u32).unwrap();
33 text(unicode_char).font(FONT_FA_REGULAR).into()
34}
35
36pub fn iced_text_icon_solid<'a, Message>(code: &str) -> Element<'a, Message> {
42 let code_u32 = u32::from_str_radix(&code, 16).unwrap();
43 let unicode_char = char::from_u32(code_u32).unwrap();
44 text(unicode_char).font(FONT_FA_SOLID).into()
45}
46
47pub const FONT_FA_REGULAR: Font = Font {
51 family: Family::Name("Font Awesome 6 Free"),
52 ..Font::DEFAULT
53};
54
55pub const FONT_FA_SOLID: Font = Font {
64 family: Family::Name("Font Awesome 6 Free"),
65 weight: Weight::Bold, ..Font::DEFAULT
67};
68
69pub const FONT_DATA_FA_REGULAR: &[u8] =
74 include_bytes!("../fonts/font-awesome-6-free-regular-400.otf");
75
76pub const FONT_DATA_FA_BRANDS: &[u8] =
77 include_bytes!("../fonts/font-awesome-6-brands-regular-400.otf");
78
79pub const FONT_DATA_FA_SOLID: &[u8] =
80 include_bytes!("../fonts/font-awesome-6-free-solid-900.otf");
81
82pub const FA_ICON_USER: &str = "f007";
88
89pub const FA_ICON_NEW: &str = "f15b";
91
92pub const FA_ICON_OPEN: &str = "f07c";
94
95pub const FA_ICON_SAVE: &str = "f0c7";
97
98pub const FA_ICON_0: &str = "30";
104
105pub const FA_ICON_1: &str = "31";
107
108pub const FA_ICON_2: &str = "32";
110
111pub const FA_ICON_3: &str = "33";
113
114pub const FA_ICON_4: &str = "34";
116
117pub const FA_ICON_5: &str = "35";
119
120pub const FA_ICON_6: &str = "36";
122
123pub const FA_ICON_7: &str = "37";
125
126pub const FA_ICON_8: &str = "38";
128
129pub const FA_ICON_9: &str = "39";
131
132pub const FA_ICON_CIRCLE_CHECK: &str = "f058";
138
139pub const FA_ICON_CIRCLE_XMARK: &str = "f057";
141
142pub const FA_ICON_BARS: &str = "f0c9";
148
149pub const FA_ICON_GEAR: &str = "f013";
153
154pub const FA_ICON_SCREWDRIVER_WRENCH: &str = "f7d9";
158
159
160#[derive(Debug, Clone, Copy, PartialEq, Eq)]
164pub enum FaIcon {
165 User,
166 CircleCheck,
167 CircleXmark,
168 ScrewdriverWrench,
169 Gear,
170 Bars,
171 New,
172 Open,
173 Save,
174 Number0,
175 Number1,
176 Number2,
177 Number3,
178 Number4,
179 Number5,
180 Number6,
181 Number7,
182 Number8,
183 Number9,
184}
185
186impl fmt::Display for FaIcon {
187 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
188 f.write_str(self.as_str())
189 }
190}
191
192impl FaIcon {
193 pub fn as_str(&self) -> &str {
194 match self {
195 FaIcon::User => "f007",
196 FaIcon::CircleCheck => "f058",
197 FaIcon::CircleXmark => "f057",
198 FaIcon::ScrewdriverWrench => "f7d9",
199 FaIcon::Gear => "f013",
200 FaIcon::Bars => "f0c9",
201 FaIcon::New => "f15b",
202 FaIcon::Open => "f07c",
203 FaIcon::Save => "f0c7",
204 FaIcon::Number0 => "30",
205 FaIcon::Number1 => "31",
206 FaIcon::Number2 => "32",
207 FaIcon::Number3 => "33",
208 FaIcon::Number4 => "34",
209 FaIcon::Number5 => "35",
210 FaIcon::Number6 => "36",
211 FaIcon::Number7 => "37",
212 FaIcon::Number8 => "38",
213 FaIcon::Number9 => "39",
214 }
215 }
216}