Loading...
Searching...
No Matches
ml::FontManager< Manifest > Class Template Reference

Manifest-driven cache for sf::Font resources. More...

#include <FontManager.h>

Inheritance diagram for ml::FontManager< Manifest >:

Static Public Member Functions

static const sf::Fontget (const Asset &asset)
 Retrieve the cached resource for an asset enum value.
static const sf::FontgetDefault ()
 Return the built-in Arial font.
static void unload (Asset asset)
 Remove a resource from the cache.

Detailed Description

template<typename Manifest = DefaultManifest>
class ml::FontManager< Manifest >

Manifest-driven cache for sf::Font resources.

FontManager<Manifest> extends ResourceManager to provide lazy-loaded, cached access to fonts declared in a manifest's Fonts enum. It also provides getDefault(), which returns a built-in Arial font that is always available without any manifest registration.

FontManager defaults to DefaultManifest so it can be used without a custom manifest when only the built-in font is needed:

// Built-in Arial — no manifest required
// Manifest-declared font
const sf::Font& main = ml::FontManager<MyManifest>::get(MyManifest::Fonts::Main);
// Via AssetsManager (preferred when multiple asset types are needed)
const sf::Font& main = ml::AssetsManager<MyManifest>::get(MyManifest::Fonts::Main);
static std::enable_if_t< has_Image< M >::value, const sf::Texture & > get(typename M::Images image)
Retrieve a cached sf::Texture by manifest enum value.
static const sf::Font & getDefault()
Return the built-in Arial font.
static const sf::Font & get(const Asset &asset)
Template Parameters
ManifestA Manifest subclass with a Fonts enum whose values map to font file paths. Defaults to DefaultManifest when no custom fonts are needed.
See also
ResourceManager, AssetsManager, DefaultManifest

FontManager.

Definition at line 45 of file FontManager.h.

Member Function Documentation

◆ get()

const sf::Font & ml::ResourceManager< DefaultManifest, sf::Font, loadFunction >::get ( const Asset & asset)
staticinherited

Retrieve the cached resource for an asset enum value.

Loads and caches on first access. Throws std::runtime_error if the path is not registered or loading fails.

Template Parameters
AssetAn enum type declared inside Manifest.
Parameters
assetThe specific enum value to load.
Returns
Const reference to the cached Resource.

◆ getDefault()

template<typename Manifest = DefaultManifest>
const sf::Font & ml::FontManager< Manifest >::getDefault ( )
static

Return the built-in Arial font.

The Arial font is embedded in the framework and requires no manifest registration or file path. Use it as a reliable fallback for UI text when no custom font has been loaded.

Returns
Const reference to the built-in sf::Font.

◆ unload()

void ml::ResourceManager< DefaultManifest, sf::Font, loadFunction >::unload ( Asset asset)
staticinherited

Remove a resource from the cache.

The next get(asset) call will reload from disk. If called during draw(), the unload is deferred until after the frame completes to prevent mid-frame dangling references.

Template Parameters
AssetThe enum type of the key to remove.
Parameters
assetThe specific enum value to evict from the cache.

The documentation for this class was generated from the following file: