use sfml::graphics::Font as SfFont; macro_rules! make_fonts { ( $( $enum_name: ident, $font_name: ident, $function_name: ident, $font_path: tt,) *) => { /// Describes all the fonts that will be used in this game. #[derive(Copy, Clone)] pub enum Font { $( /// A font. $enum_name, )* } /// A struct that holds all the fonts. pub struct FontManager { $( /// A font. $font_name: SfFont, )* } impl FontManager { /// Creates a new font manager and initializes all fonts. pub fn new() -> FontManager { FontManager { $( $font_name: FontManager::$function_name(), )* } } $( /// Creates the font. fn $function_name() -> SfFont { SfFont::from_file("assets/fonts/sansation.ttf").unwrap() // let bytes = include_bytes!($font_path).to_vec(); // FontManager::make_font_from_bytes(bytes) } )* /// Returns the real font from the font id. pub fn get(&self, id: Font) -> &SfFont { match id { $( Font::$enum_name => &self.$font_name, )* } } } } } make_fonts!( Sansation, sansation, make_sansation_font, "../../../assets/fonts/sansation.ttf", ); impl FontManager { /// Creates a fonts from an array of bytes. fn _make_font_from_bytes(bytes: Vec) -> SfFont { SfFont::from_memory(&bytes).expect("Failed to create font") } }