1use std::borrow::Cow;
8use iced::advanced::graphics::text::font_system;
9use iced::{Element, Font};
10use iced::font::Family;
11use iced::widget::text;
12use std::fmt;
13use std::str::FromStr;
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<'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 const FONT_FA_REGULAR: Font = Font {
40 family: Family::Name("Font Awesome 6 Free"),
41 ..Font::DEFAULT
42};
43
44const FONT_DATA_FA_REGULAR: &[u8] =
49 include_bytes!("../fonts/font-awesome-6-free-regular-400.otf");
50
51const FONT_DATA_FA_BRANDS: &[u8] =
52 include_bytes!("../fonts/font-awesome-6-brands-regular-400.otf");
53
54const FONT_DATA_FA_SOLID: &[u8] =
55 include_bytes!("../fonts/font-awesome-6-free-solid-900.otf");
56
57pub const FA_ICON_USER: &str = "f007";
63
64pub const FA_ICON_NEW: &str = "f15b";
66
67pub const FA_ICON_OPEN: &str = "f07c";
69
70pub const FA_ICON_SAVE: &str = "f0c7";
72
73pub const FA_ICON_0: &str = "30";
79
80pub const FA_ICON_1: &str = "31";
82
83pub const FA_ICON_2: &str = "32";
85
86pub const FA_ICON_3: &str = "33";
88
89pub const FA_ICON_4: &str = "34";
91
92pub const FA_ICON_5: &str = "35";
94
95pub const FA_ICON_6: &str = "36";
97
98pub const FA_ICON_7: &str = "37";
100
101pub const FA_ICON_8: &str = "38";
103
104pub const FA_ICON_9: &str = "39";
106
107pub const FA_ICON_CIRCLE_CHECK: &str = "f058";
113
114pub const FA_ICON_CIRCLE_XMARK: &str = "f057";
116
117pub const FA_ICON_BARS: &str = "f0c9";
123
124pub const FA_ICON_GEAR: &str = "f013";
126
127pub const FA_ICON_SCREWDRIVER_WRENCH: &str = "f7d9";
129
130
131#[derive(Debug, Clone, Copy, PartialEq, Eq)]
135pub enum FaIcon {
136 User,
137 CircleCheck,
138 CircleXmark,
139 ScrewdriverWrench,
140 Gear,
141 Bars,
142 New,
143 Open,
144 Save,
145 Number0,
146 Number1,
147 Number2,
148 Number3,
149 Number4,
150 Number5,
151 Number6,
152 Number7,
153 Number8,
154 Number9,
155}
156
157impl fmt::Display for FaIcon {
158 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159 f.write_str(self.as_str())
160 }
161}
162
163impl FaIcon {
164 pub fn as_str(&self) -> &str {
165 match self {
166 FaIcon::User => "f007",
167 FaIcon::CircleCheck => "f058",
168 FaIcon::CircleXmark => "f057",
169 FaIcon::ScrewdriverWrench => "f7d9",
170 FaIcon::Gear => "f013",
171 FaIcon::Bars => "f0c9",
172 FaIcon::New => "f15b",
173 FaIcon::Open => "f07c",
174 FaIcon::Save => "f0c7",
175 FaIcon::Number0 => "30",
176 FaIcon::Number1 => "31",
177 FaIcon::Number2 => "32",
178 FaIcon::Number3 => "33",
179 FaIcon::Number4 => "34",
180 FaIcon::Number5 => "35",
181 FaIcon::Number6 => "36",
182 FaIcon::Number7 => "37",
183 FaIcon::Number8 => "38",
184 FaIcon::Number9 => "39",
185 }
186 }
187}