use std::fmt;
pub const CUPERTINO_ICONS_FONT_BYTES: &[u8] =
include_bytes!("../../assets/fonts/CupertinoIcons.ttf");
pub const CUPERTINO_ICONS_FONT_NAME: &str = "cupertino_icons";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MacSymbol {
Search,
ChevronRight,
ChevronLeft,
ChevronDown,
ChevronUp,
SidebarLeading,
Gear,
Sliders,
Checkmark,
Xmark,
Plus,
Minus,
ArrowClockwise,
ArrowCounterClockwise,
}
impl MacSymbol {
pub const ALL: [Self; 14] = [
Self::Search,
Self::ChevronRight,
Self::ChevronLeft,
Self::ChevronDown,
Self::ChevronUp,
Self::SidebarLeading,
Self::Gear,
Self::Sliders,
Self::Checkmark,
Self::Xmark,
Self::Plus,
Self::Minus,
Self::ArrowClockwise,
Self::ArrowCounterClockwise,
];
#[inline]
pub const fn as_char(&self) -> char {
match self {
Self::Search => '\u{f4a5}',
Self::ChevronRight => '\u{f3d3}',
Self::ChevronLeft => '\u{f3d2}',
Self::ChevronDown => '\u{f5d5}',
Self::ChevronUp => '\u{f5e5}',
Self::SidebarLeading => '\u{f7d6}',
Self::Gear => '\u{f43c}',
Self::Sliders => '\u{f7dc}',
Self::Checkmark => '\u{f3fd}',
Self::Xmark => '\u{f404}',
Self::Plus => '\u{f489}',
Self::Minus => '\u{f70f}',
Self::ArrowClockwise => '\u{f49a}',
Self::ArrowCounterClockwise => '\u{f21c}',
}
}
#[inline]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Search => "\u{f4a5}",
Self::ChevronRight => "\u{f3d3}",
Self::ChevronLeft => "\u{f3d2}",
Self::ChevronDown => "\u{f5d5}",
Self::ChevronUp => "\u{f5e5}",
Self::SidebarLeading => "\u{f7d6}",
Self::Gear => "\u{f43c}",
Self::Sliders => "\u{f7dc}",
Self::Checkmark => "\u{f3fd}",
Self::Xmark => "\u{f404}",
Self::Plus => "\u{f489}",
Self::Minus => "\u{f70f}",
Self::ArrowClockwise => "\u{f49a}",
Self::ArrowCounterClockwise => "\u{f21c}",
}
}
#[inline]
pub const fn codepoint(&self) -> u32 {
self.as_char() as u32
}
}
impl fmt::Display for MacSymbol {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl AsRef<str> for MacSymbol {
#[inline]
fn as_ref(&self) -> &str {
self.as_str()
}
}
pub fn setup_symbols_font(fonts: &mut egui::FontDefinitions) {
fonts.font_data.insert(
CUPERTINO_ICONS_FONT_NAME.to_owned(),
std::sync::Arc::new(egui::FontData::from_static(CUPERTINO_ICONS_FONT_BYTES)),
);
let prop_family = fonts
.families
.entry(egui::FontFamily::Proportional)
.or_default();
if !prop_family.iter().any(|f| f == CUPERTINO_ICONS_FONT_NAME) {
prop_family.push(CUPERTINO_ICONS_FONT_NAME.to_owned());
}
let mono_family = fonts
.families
.entry(egui::FontFamily::Monospace)
.or_default();
if !mono_family.iter().any(|f| f == CUPERTINO_ICONS_FONT_NAME) {
mono_family.push(CUPERTINO_ICONS_FONT_NAME.to_owned());
}
}