2020-05-25 18:11:39 +00:00
|
|
|
use crate::i18n;
|
2020-08-28 01:02:17 +00:00
|
|
|
use common::assets::Asset;
|
2020-01-26 19:29:46 +00:00
|
|
|
|
2020-05-25 18:11:39 +00:00
|
|
|
pub struct Font {
|
|
|
|
metadata: i18n::Font,
|
2020-01-26 19:29:46 +00:00
|
|
|
pub conrod_id: conrod_core::text::font::Id,
|
|
|
|
}
|
|
|
|
|
2020-05-25 18:11:39 +00:00
|
|
|
impl Font {
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::needless_return)] // TODO: Pending review in #587
|
2020-05-25 18:11:39 +00:00
|
|
|
pub fn new(font: &i18n::Font, ui: &mut crate::ui::Ui) -> Font {
|
2020-01-26 19:29:46 +00:00
|
|
|
return Self {
|
|
|
|
metadata: font.clone(),
|
2020-08-28 01:02:17 +00:00
|
|
|
conrod_id: ui.new_font(crate::ui::Font::load_expect(&font.asset_key)),
|
2020-01-26 19:29:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Scale input size to final UI size
|
|
|
|
pub fn scale(&self, value: u32) -> u32 { self.metadata.scale(value) }
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! conrod_fonts {
|
|
|
|
($([ $( $name:ident$(,)? )* ])*) => {
|
|
|
|
$(
|
2020-05-25 18:11:39 +00:00
|
|
|
pub struct Fonts {
|
|
|
|
$(pub $name: Font,)*
|
2020-01-26 19:29:46 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 18:11:39 +00:00
|
|
|
impl Fonts {
|
|
|
|
pub fn load(fonts: &i18n::Fonts, ui: &mut crate::ui::Ui) -> Result<Self, common::assets::Error> {
|
2020-01-26 19:29:46 +00:00
|
|
|
Ok(Self {
|
2020-05-25 18:11:39 +00:00
|
|
|
$( $name: Font::new(fonts.get(stringify!($name)).unwrap(), ui),)*
|
2020-01-26 19:29:46 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
conrod_fonts! {
|
|
|
|
[opensans, metamorph, alkhemi, cyri, wizard]
|
|
|
|
}
|