Loading...
Searching...
No Matches
ml::Themeable Class Referenceabstract

Trait that makes a component react to global theme changes. More...

#include <Malena/Traits/Theme/Themeable.h>

Inherits ml::Trait.

Inherited by ml::ButtonToggle, ml::Checkbox, ml::CheckboxGroup, ml::List, ml::ListItem, ml::MenuBar, ml::Panel, ml::PillToggle, ml::RadioButton, ml::RadioGroup, ml::SegmentToggle, ml::Select, ml::SideMenu, ml::SplitPanel, ml::TabbedPanel, ml::TextInput, and ml::Toolbar.

Public Member Functions

 Themeable ()
virtual ~Themeable ()
bool isSettingsLocked () const
 Return true if applySettings() is currently blocked.
bool isThemeLocked () const
 Return true if this component ignores theme changes.
void lockSettings ()
 Prevent applySettings() from taking effect.
void lockTheme ()
 Prevent automatic re-styling when the global theme changes.
virtual void onThemeApplied (const Theme &theme)=0
 Called by ThemeManager when the active theme changes.
void unlockSettings ()
 Allow applySettings() to take effect again.
void unlockTheme ()
 Resume reacting to global theme changes.

Detailed Description

Trait that makes a component react to global theme changes.

Any component that inherits Themeable automatically subscribes to ThemeManager on construction and unsubscribes on destruction. When ThemeManager::apply() or ThemeManager::set() is called, every subscribed component's onThemeApplied() is invoked.

Adding Themeable to a component

class PillToggle : public ComponentWith<PillToggleManifest>,
public PillSettings,
public PillTheme,
public Themeable
{
protected:
void onThemeApplied(const Theme& theme) override
{
if (isThemeLocked()) return;
PillTheme::applyFrom(theme); // walks full theme chain
syncFromSettings(); // pushes values to SFML shapes
}
};
iOS-style oval pill switch with animated sliding thumb.
Definition PillToggle.h:70
bool isThemeLocked() const
Return true if this component ignores theme changes.
Definition Themeable.h:97
virtual void onThemeApplied(const Theme &theme)=0
Called by ThemeManager when the active theme changes.
Component< M, Traits... > ComponentWith
Alias for Component<M, Traits...>.
Definition Component.h:299
Layout and behaviour settings for PillToggle.
Theme tokens for the PillToggle (iOS-style oval switch).
Definition PillTheme.h:48
PillTheme & applyFrom(const Theme &t) override
Populate all fields from the global Theme token set.
Definition PillTheme.h:58
Universal design token set applied across all Themeable components.
Definition Theme.h:70

Locking a component from theme changes

toggle.lockTheme(); // ignores all future theme changes
toggle.unlockTheme(); // resumes reacting to theme changes

Locking a component from settings changes

toggle.lockSettings(); // applySettings() has no effect
toggle.unlockSettings(); // applySettings() works again

Explicit calls to individual setters (e.g. setTrackOnColor()) always take effect regardless of lock state — locks only block automatic updates from ThemeManager and applySettings().

See also
ThemeManager, Theme, Trait

Definition at line 62 of file Themeable.h.

Constructor & Destructor Documentation

◆ Themeable()

ml::Themeable::Themeable ( )
inline

Definition at line 67 of file Themeable.h.

◆ ~Themeable()

virtual ml::Themeable::~Themeable ( )
inlinevirtual

Definition at line 72 of file Themeable.h.

Member Function Documentation

◆ isSettingsLocked()

bool ml::Themeable::isSettingsLocked ( ) const
inlinenodiscard

Return true if applySettings() is currently blocked.

Definition at line 115 of file Themeable.h.

◆ isThemeLocked()

bool ml::Themeable::isThemeLocked ( ) const
inlinenodiscard

Return true if this component ignores theme changes.

Definition at line 97 of file Themeable.h.

◆ lockSettings()

void ml::Themeable::lockSettings ( )
inline

Prevent applySettings() from taking effect.

Explicit individual setter calls still work normally. Only blocks the batch applySettings() path.

Definition at line 107 of file Themeable.h.

◆ lockTheme()

void ml::Themeable::lockTheme ( )
inline

Prevent automatic re-styling when the global theme changes.

The component keeps its current visual state. Explicit individual setter calls still work normally.

Definition at line 85 of file Themeable.h.

◆ onThemeApplied()

virtual void ml::Themeable::onThemeApplied ( const Theme & theme)
pure virtual

Called by ThemeManager when the active theme changes.

Override in your component to re-style from the new theme. Always check isThemeLocked() first:

void onThemeApplied(const Theme& theme) override
{
if (isThemeLocked()) return;
MySettings::applyTheme(theme);
syncFromSettings();
}
Parameters
themeThe newly active theme.

Implemented in ml::ButtonToggle, ml::Checkbox, ml::CheckboxGroup, ml::List, ml::ListItem, ml::MenuBar, ml::Panel, ml::PillToggle, ml::RadioButton, ml::RadioGroup, ml::SegmentToggle, ml::Select, ml::SideMenu, ml::SplitPanel, ml::TabbedPanel, ml::TextArea, ml::TextInput, and ml::Toolbar.

◆ unlockSettings()

void ml::Themeable::unlockSettings ( )
inline

Allow applySettings() to take effect again.

Definition at line 112 of file Themeable.h.

◆ unlockTheme()

void ml::Themeable::unlockTheme ( )
inline

Resume reacting to global theme changes.

Does NOT immediately re-apply the current theme — call ThemeManager::get() and pass it to onThemeApplied() manually if you want to re-sync immediately after unlocking.

Definition at line 94 of file Themeable.h.


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