Global manager for the active Theme.
More...
#include <Malena/Resources/ThemeManager.h>
|
| 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 Theme & | get () |
| | 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 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 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.
|
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
static void apply(typename MANIFEST::Themes themeKey)
Apply a theme stored in a Manifest enum.
Reading the active theme
static const Theme & get()
Return a const reference to the currently active theme.
Universal design token set applied across all Themeable components.
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.
- See also
- Theme, Themeable, DarkTheme, LightTheme, DeferredOperationsManager
Definition at line 56 of file ThemeManager.h.
◆ 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
-
| MANIFEST | A Manifest subclass declaring a Themes enum. |
- Parameters
-
| themeKey | Enum value identifying which theme to apply. |
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
-
| MANIFEST | A Manifest subclass declaring a Themes enum. |
- Parameters
-
| themeKey | Enum value identifying which theme to apply. |
Definition at line 99 of file ThemeManager.h.
◆ beginBusy()
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()
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()
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
-
| operation | The callable to execute or defer. |
◆ endBusy()
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()
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()
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
-
| T | A type derived from Theme. |
- Parameters
-
| theme | The theme instance to apply. Copied internally. |
Definition at line 116 of file ThemeManager.h.
◆ shutdown()
| void ml::ThemeManager::shutdown |
( |
| ) |
|
|
static |
◆ 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.
◆ busyDepth
|
|
inlinestaticprotectedinherited |
◆ pendingOperations
|
|
inlinestaticprotectedinherited |
The documentation for this class was generated from the following file: