Loading...
Searching...
No Matches
ml::ThemeManager Class Reference

Global manager for the active Theme. More...

#include <Malena/Resources/ThemeManager.h>

Inheritance diagram for ml::ThemeManager:
[legend]

Static Public Member Functions

template<typename MANIFEST>
static void apply (typename MANIFEST::Themes themeKey)
 Apply a theme stored in a Manifest enum.
static void clearPending ()
 Discard all pending operations without executing them.
static const Themeget ()
 Return a const reference to the currently active theme.
static bool isBusy ()
 Return true if the manager is currently iterating.
static void processPending ()
 Flush all pending operations immediately.
template<typename T>
static void set (const T &theme)
 Apply a theme instance directly without a manifest.
static void shutdown ()
 Shut down the theme system.
static void subscribe (Themeable *component)
 Subscribe a component to theme change notifications.
static void unsubscribe (Themeable *component)
 Unsubscribe a component from theme change notifications.

Static Protected Member Functions

static void beginBusy ()
 Signal that iteration has begun.
static void deferOrExecute (std::function< void()> operation)
 Execute operation now if safe, otherwise queue it.
static void endBusy ()
 Signal that iteration has ended; flush pending operations.

Static Protected Attributes

static int busyDepth
 Iteration nesting depth. Operations are deferred while this is > 0.
static std::vector< std::function< void()> > pendingOperations
 Queue of operations pending until the current iteration completes.

Detailed Description

Global manager for the active Theme.

ThemeManager holds one active Theme at a time and notifies all subscribed Themeable components when it changes. Components subscribe automatically by inheriting Themeable — no manual registration needed.

Inherits DeferredOperationsManager so that subscribe() and unsubscribe() calls made during a theme notification (e.g. a component creating children inside onThemeApplied()) are safely deferred until the current iteration completes.

Switching themes at runtime

ml::ThemeManager::apply<GameManifest>(GameManifest::Themes::GameOver);
static void apply(typename MANIFEST::Themes themeKey)
Apply a theme stored in a Manifest enum.

Reading the active theme

sf::Color primary = t.primary;
static const Theme & get()
Return a const reference to the currently active theme.
Universal design token set applied across all Themeable components.
Definition Theme.h:70
sf::Color primary
Definition Theme.h:74

Setting a theme directly (without a manifest)

static void set(const T &theme)
Apply a theme instance directly without a manifest.
Malena default dark theme.
Definition Theme.h:155
See also
Theme, Themeable, DarkTheme, LightTheme, DeferredOperationsManager

Definition at line 56 of file ThemeManager.h.

Member Function Documentation

◆ apply()

template<typename MANIFEST>
void ml::ThemeManager::apply ( typename MANIFEST::Themes themeKey)
inlinestatic

Apply a theme stored in a Manifest enum.

Retrieves the theme registered under themeKey, sets it as the active theme, and notifies all subscribed Themeable components.

Template Parameters
MANIFESTA Manifest subclass declaring a Themes enum.
Parameters
themeKeyEnum value identifying which theme to apply.
ml::ThemeManager::apply<GameManifest>(GameManifest::Themes::Home);

Apply a theme registered via Manifest::set().

Retrieves the theme stored in ThemeStore by Manifest::set(), casts it back to Theme, and notifies all subscribed Themeable components.

Template Parameters
MANIFESTA Manifest subclass declaring a Themes enum.
Parameters
themeKeyEnum value identifying which theme to apply.
ml::ThemeManager::apply<GameManifest>(GameManifest::Themes::Home);

Definition at line 99 of file ThemeManager.h.

◆ beginBusy()

void ml::DeferredOperationsManager< ThemeManager >::beginBusy ( )
staticprotectedinherited

Signal that iteration has begun.

Increments the busy-depth counter. Multiple nested calls are safe — operations remain deferred until the outermost endBusy() is reached.

◆ clearPending()

void ml::DeferredOperationsManager< ThemeManager >::clearPending ( )
staticinherited

Discard all pending operations without executing them.

Use during application shutdown or full reset when executing the queued operations would be unsafe (e.g., the objects they reference have already been destroyed).

◆ deferOrExecute()

void ml::DeferredOperationsManager< ThemeManager >::deferOrExecute ( std::function< void()> operation)
staticprotectedinherited

Execute operation now if safe, otherwise queue it.

If busyDepth > 0 the operation is appended to pendingOperations and will run when the current iteration completes. If the manager is idle the operation executes immediately.

Parameters
operationThe callable to execute or defer.

◆ endBusy()

void ml::DeferredOperationsManager< ThemeManager >::endBusy ( )
staticprotectedinherited

Signal that iteration has ended; flush pending operations.

Decrements the busy-depth counter. When the counter reaches zero, all operations in pendingOperations are executed in FIFO order and the queue is cleared.

◆ get()

const Theme & ml::ThemeManager::get ( )
static

Return a const reference to the currently active theme.

Safe to call at any time including during component construction. Defaults to DarkTheme before any theme has been applied.

◆ isBusy()

bool ml::DeferredOperationsManager< ThemeManager >::isBusy ( )
staticinherited

Return true if the manager is currently iterating.

Can be used by external code that needs to know whether a destructive operation will be deferred.

Returns
true when busyDepth > 0.

◆ processPending()

void ml::DeferredOperationsManager< ThemeManager >::processPending ( )
staticinherited

Flush all pending operations immediately.

Normally called automatically by endBusy(). Provided as a public escape hatch for unusual teardown sequences.

Warning
Calling this while isBusy() is true can cause iterator invalidation in the currently running loop. Only call manually when you are certain it is safe.

◆ set()

template<typename T>
void ml::ThemeManager::set ( const T & theme)
inlinestatic

Apply a theme instance directly without a manifest.

Template Parameters
TA type derived from Theme.
Parameters
themeThe theme instance to apply. Copied internally.
ml::ThemeManager::set(NeonTheme());

Definition at line 116 of file ThemeManager.h.

◆ shutdown()

void ml::ThemeManager::shutdown ( )
static

Shut down the theme system.

Called automatically by ApplicationBase::~ApplicationBase(). Clears all subscribers and discards any pending deferred operations. After this call, subscribe() and unsubscribe() are no-ops.

◆ subscribe()

void ml::ThemeManager::subscribe ( Themeable * component)
static

Subscribe a component to theme change notifications.

Called automatically by the Themeable constructor. Safe to call during a theme notification — deferred if necessary.

◆ unsubscribe()

void ml::ThemeManager::unsubscribe ( Themeable * component)
static

Unsubscribe a component from theme change notifications.

Called automatically by the Themeable destructor. Safe to call during a theme notification — deferred if necessary.

Member Data Documentation

◆ busyDepth

int ml::DeferredOperationsManager< ThemeManager >::busyDepth
inlinestaticprotectedinherited

Iteration nesting depth. Operations are deferred while this is > 0.

Definition at line 70 of file DeferredOperationsManager.h.

◆ pendingOperations

std::vector<std::function<void()> > ml::DeferredOperationsManager< ThemeManager >::pendingOperations
inlinestaticprotectedinherited

Queue of operations pending until the current iteration completes.

Definition at line 73 of file DeferredOperationsManager.h.


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