Created
July 17, 2024 14:09
-
-
Save airstrike/2991997aebc2843b9a547c1674c0464c to your computer and use it in GitHub Desktop.
iced fonts modified from halloy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::borrow::Cow; | |
use std::sync::OnceLock; | |
use iced::font; | |
pub static SANS: Font = Font::new(false); | |
pub static SANS_BOLD: Font = Font::new(true); | |
pub static MONOSPACE: iced::Font = iced::Font::MONOSPACE; | |
pub const ICON: iced::Font = iced::Font::with_name("bootstrap-icons"); | |
#[derive(Debug, Clone)] | |
pub struct Font { | |
bold: bool, | |
inner: OnceLock<iced::Font>, | |
} | |
impl Font { | |
const fn new(bold: bool) -> Self { | |
Self { | |
bold, | |
inner: OnceLock::new(), | |
} | |
} | |
fn set(&self, name: String) { | |
let name = Box::leak(name.into_boxed_str()); | |
let weight = if self.bold { | |
font::Weight::Bold | |
} else { | |
font::Weight::Normal | |
}; | |
let _ = self.inner.set(iced::Font { | |
weight, | |
..iced::Font::with_name(name) | |
}); | |
} | |
} | |
impl From<Font> for iced::Font { | |
fn from(value: Font) -> Self { | |
value.inner.get().copied().expect("font is set on startup") | |
} | |
} | |
pub fn set() { | |
SANS.set("Config Regular".to_string()); | |
SANS_BOLD.set("Config Bold".to_string()); | |
} | |
pub fn load() -> Vec<Cow<'static, [u8]>> { | |
vec![ | |
include_bytes!("../assets/fonts/Config Regular.ttf") | |
.as_slice() | |
.into(), | |
include_bytes!("../assets/fonts/Config Bold.ttf") | |
.as_slice() | |
.into(), | |
include_bytes!("../assets/fonts/Config Italic.ttf") | |
.as_slice() | |
.into(), | |
include_bytes!("../assets/fonts/Config Bold Italic.ttf") | |
.as_slice() | |
.into(), | |
include_bytes!("../assets/fonts/bootstrap-icons.ttf") | |
.as_slice() | |
.into(), | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment