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

A centered overlay dialog with optional title, content, and action buttons. More...

#include <Malena/Graphics/Controls/Modal.h>

Inheritance diagram for ml::Modal:
[legend]

Public Types

using Flag = ModalManifest::Flag
using State = ModalManifest::State

Public Member Functions

 Modal (const sf::Font &font=FontManager<>::getDefault())
ModalThemeapplyFrom (const Theme &t) override
 Populate all fields from the global Theme token set.
template<typename S>
void applySettings (const S &s)
template<typename St>
void applyStyle (const St &s)
template<typename T>
void applyTheme (const T &t)
sf::Color getDisabledColor () const
sf::Color getDisabledTextColor () const
sf::Color getErrorColor () const
sf::Color getFillColor () const
sf::Color getFocusColor () const
const sf::FontgetFont () const
unsigned int getFontSize () const
unsigned int getFontSizeSmall () const
sf::FloatRect getGlobalBounds () const override
sf::Color getHoverColor () const
sf::Color getMutedColor () const
sf::Color getOutlineColor () const
float getOutlineThickness () const
float getPadding () const
sf::Vector2f getPosition () const override
float getRadius () const
sf::Color getTextColor () const
void hide ()
bool isSettingsLocked () const
 Return true if applySettings() is currently blocked.
bool isThemeLocked () const
 Return true if this component ignores theme changes.
bool isVisible () const
void lockSettings ()
 Prevent applySettings() from taking effect.
void lockTheme ()
 Prevent automatic re-styling when the global theme changes.
void onConfirm (std::function< void()> cb)
 Fired when the confirm button is clicked.
void onDismiss (std::function< void()> cb)
 Fired when dismissed — cancel button, close button, or backdrop tap.
void setBackdropColor (const sf::Color &c)
void setBodyTextColor (const sf::Color &c)
void setBtnTextColor (const sf::Color &c)
void setButtonBarHeight (float h)
void setCancelColor (const sf::Color &c)
void setCancelLabel (const std::string &label)
 Label for the cancel button. Pass empty to show only the confirm button.
void setCloseBtnColor (const sf::Color &c)
void setConfirmColor (const sf::Color &c)
void setConfirmLabel (const std::string &label)
 Label for the confirm button. Pass empty to hide the button bar.
void setContent (ml::Core &content)
 Component drawn in the content area. The Modal positions it.
void setCornerRadius (float r)
void setDisabledColor (const sf::Color &c)
void setDisabledTextColor (const sf::Color &c)
void setDismissOnBackdrop (bool v)
void setErrorColor (const sf::Color &c)
void setFillColor (const sf::Color &c)
void setFocusColor (const sf::Color &c)
void setFont (const sf::Font &&)=delete
void setFont (const sf::Font &f)
void setFontSize (unsigned int s)
void setFontSizeSmall (unsigned int s)
void setHoverColor (const sf::Color &c)
void setModalSize (const sf::Vector2f &s)
void setMutedColor (const sf::Color &c)
void setOutlineColor (const sf::Color &c)
void setOutlineThickness (float t)
void setPadding (float p)
void setPanelColor (const sf::Color &c)
void setPosition (const sf::Vector2f &pos) override
void setRadius (float r)
void setSeparatorColor (const sf::Color &c)
void setShowCloseButton (bool v)
void setTextColor (const sf::Color &c)
void setTitle (const std::string &title)
 Text displayed in the title bar. Pass an empty string to hide it.
void setTitleBarHeight (float h)
void setTitleTextColor (const sf::Color &c)
void show ()
void showImmediate ()
void toggle ()
void unlockSettings ()
 Allow applySettings() to take effect again.
void unlockTheme ()
 Resume reacting to global theme changes.

Public Attributes

sf::Color backdropColor = sf::Color(0, 0, 0, 160)
sf::Color bodyTextColor = sf::Color(200, 200, 200)
sf::Color btnTextColor = sf::Color::White
float buttonBarHeight = 56.f
sf::Color cancelColor = sf::Color(70, 70, 70)
sf::Color closeBtnColor = sf::Color(160, 160, 160)
sf::Color confirmColor = sf::Color(0, 122, 255)
float cornerRadius = 12.f
sf::Color disabledColor = sf::Color(60, 60, 60)
sf::Color disabledTextColor = sf::Color(120, 120, 120)
bool dismissOnBackdrop = true
sf::Color errorColor = sf::Color(220, 70, 70)
sf::Color fillColor = sf::Color(40, 40, 40)
sf::Color focusColor = sf::Color(100, 60, 200)
const sf::Fontfont = &FontManager<>::getDefault()
unsigned int fontSize = 14
unsigned int fontSizeSmall = 11
sf::Color hoverColor = sf::Color(70, 130, 230)
sf::Vector2f modalSize = {420.f, 300.f}
sf::Color mutedColor = sf::Color(120, 120, 120)
sf::Color outlineColor = sf::Color(100, 100, 100)
float outlineThickness = 1.5f
float padding = 8.f
sf::Color panelColor = sf::Color(36, 36, 50)
float radius = 8.f
sf::Color separatorColor = sf::Color(60, 60, 80)
bool showCloseButton = true
sf::Color textColor = sf::Color::White
float titleBarHeight = 50.f
sf::Color titleTextColor = sf::Color::White

Protected Member Functions

void draw (sf::RenderTarget &target, sf::RenderStates states) const override
void onThemeApplied (const Theme &theme) override
 Called by ThemeManager when the active theme changes.

Detailed Description

A centered overlay dialog with optional title, content, and action buttons.

Modal renders a backdrop over the full window and a centered panel with an optional title bar, custom content area, and confirm/cancel buttons.

The panel is always centered in the window. All interaction — backdrop dismiss, close button, confirm, cancel — is handled internally and exposed via callbacks.

Usage

ml::Modal modal;
modal.setTitle("Confirm Action");
modal.setConfirmLabel("OK");
modal.setCancelLabel("Cancel");
modal.onConfirm([this]{ doAction(); });
modal.onDismiss([this]{ /* nothing *\/ });
* addComponent(modal);
*
* // Show it in response to a button click:
* someBtn.onClick([this]{ modal.show(); });
*
A centered overlay dialog with optional title, content, and action buttons.
Definition Modal.h:74
void setConfirmLabel(const std::string &label)
Label for the confirm button. Pass empty to hide the button bar.
void setCancelLabel(const std::string &label)
Label for the cancel button. Pass empty to show only the confirm button.
void setTitle(const std::string &title)
Text displayed in the title bar. Pass an empty string to hide it.
void onConfirm(std::function< void()> cb)
Fired when the confirm button is clicked.
void onDismiss(std::function< void()> cb)
Fired when dismissed — cancel button, close button, or backdrop tap.

Custom content

body.setString("Are you sure you want to delete this item?");
modal.setContent(body);
void setContent(ml::Core &content)
Component drawn in the content area. The Modal positions it.
Multi-line text display area. (Currently a stub — not yet implemented.).
Definition TextBox.h:28

With a manifest

class MyModal : public ml::ModalWith<MyManifest> {};
Modal with an attached manifest.
Definition Modal.h:207
See also
ModalSettings, ModalTheme, SideMenu

Definition at line 70 of file Modal.h.

Member Typedef Documentation

◆ Flag

Definition at line 76 of file Modal.h.

◆ State

Definition at line 77 of file Modal.h.

Constructor & Destructor Documentation

◆ Modal()

ml::Modal::Modal ( const sf::Font & font = FontManager<>::getDefault())
explicit

Member Function Documentation

◆ applyFrom()

ModalTheme & ml::ModalTheme::applyFrom ( const Theme & t)
inlineoverridevirtualinherited

Populate all fields from the global Theme token set.

Subclasses call GraphicTheme::applyFrom(t) first, then apply their own token mappings.

Reimplemented from ml::ControlTheme.

Definition at line 23 of file ModalTheme.h.

◆ applySettings()

template<typename S>
void ml::Modal::applySettings ( const S & s)
inline

Definition at line 167 of file Modal.h.

◆ applyStyle()

template<typename St>
void ml::Modal::applyStyle ( const St & s)
inline

Definition at line 184 of file Modal.h.

◆ applyTheme()

template<typename T>
void ml::Modal::applyTheme ( const T & t)
inline

Definition at line 176 of file Modal.h.

◆ draw()

void ml::Modal::draw ( sf::RenderTarget & target,
sf::RenderStates states ) const
overrideprotected

◆ getDisabledColor()

sf::Color ml::ControlTheme::getDisabledColor ( ) const
inlinenodiscardinherited

Definition at line 75 of file ControlTheme.h.

◆ getDisabledTextColor()

sf::Color ml::ControlTheme::getDisabledTextColor ( ) const
inlinenodiscardinherited

Definition at line 76 of file ControlTheme.h.

◆ getErrorColor()

sf::Color ml::ControlTheme::getErrorColor ( ) const
inlinenodiscardinherited

Definition at line 74 of file ControlTheme.h.

◆ getFillColor()

sf::Color ml::GraphicTheme::getFillColor ( ) const
inlinenodiscardinherited

Definition at line 67 of file GraphicTheme.h.

◆ getFocusColor()

sf::Color ml::ControlTheme::getFocusColor ( ) const
inlinenodiscardinherited

Definition at line 73 of file ControlTheme.h.

◆ getFont()

const sf::Font * ml::ControlTheme::getFont ( ) const
inlinenodiscardinherited

Definition at line 80 of file ControlTheme.h.

◆ getFontSize()

unsigned int ml::ControlTheme::getFontSize ( ) const
inlinenodiscardinherited

Definition at line 81 of file ControlTheme.h.

◆ getFontSizeSmall()

unsigned int ml::ControlTheme::getFontSizeSmall ( ) const
inlinenodiscardinherited

Definition at line 82 of file ControlTheme.h.

◆ getGlobalBounds()

sf::FloatRect ml::Modal::getGlobalBounds ( ) const
override

◆ getHoverColor()

sf::Color ml::ControlTheme::getHoverColor ( ) const
inlinenodiscardinherited

Definition at line 72 of file ControlTheme.h.

◆ getMutedColor()

sf::Color ml::ControlTheme::getMutedColor ( ) const
inlinenodiscardinherited

Definition at line 78 of file ControlTheme.h.

◆ getOutlineColor()

sf::Color ml::GraphicTheme::getOutlineColor ( ) const
inlinenodiscardinherited

Definition at line 68 of file GraphicTheme.h.

◆ getOutlineThickness()

float ml::GraphicTheme::getOutlineThickness ( ) const
inlinenodiscardinherited

Definition at line 69 of file GraphicTheme.h.

◆ getPadding()

float ml::ControlTheme::getPadding ( ) const
inlinenodiscardinherited

Definition at line 79 of file ControlTheme.h.

◆ getPosition()

sf::Vector2f ml::Modal::getPosition ( ) const
override

◆ getRadius()

float ml::GraphicTheme::getRadius ( ) const
inlinenodiscardinherited

Definition at line 70 of file GraphicTheme.h.

◆ getTextColor()

sf::Color ml::ControlTheme::getTextColor ( ) const
inlinenodiscardinherited

Definition at line 77 of file ControlTheme.h.

◆ hide()

void ml::Modal::hide ( )

◆ isSettingsLocked()

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

Return true if applySettings() is currently blocked.

Definition at line 115 of file Themeable.h.

◆ isThemeLocked()

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

Return true if this component ignores theme changes.

Definition at line 97 of file Themeable.h.

◆ isVisible()

bool ml::Modal::isVisible ( ) const
nodiscard

◆ lockSettings()

void ml::Themeable::lockSettings ( )
inlineinherited

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 ( )
inlineinherited

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.

◆ onConfirm()

void ml::Modal::onConfirm ( std::function< void()> cb)

Fired when the confirm button is clicked.

◆ onDismiss()

void ml::Modal::onDismiss ( std::function< void()> cb)

Fired when dismissed — cancel button, close button, or backdrop tap.

◆ onThemeApplied()

void ml::Modal::onThemeApplied ( const Theme & theme)
overrideprotectedvirtual

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();
}
void onThemeApplied(const Theme &theme) override
Called by ThemeManager when the active theme changes.
bool isThemeLocked() const
Return true if this component ignores theme changes.
Definition Themeable.h:97
Universal design token set applied across all Themeable components.
Definition Theme.h:70
Parameters
themeThe newly active theme.

Implements ml::Themeable.

◆ setBackdropColor()

void ml::ModalTheme::setBackdropColor ( const sf::Color & c)
inlineinherited

Definition at line 42 of file ModalTheme.h.

◆ setBodyTextColor()

void ml::ModalTheme::setBodyTextColor ( const sf::Color & c)
inlineinherited

Definition at line 45 of file ModalTheme.h.

◆ setBtnTextColor()

void ml::ModalTheme::setBtnTextColor ( const sf::Color & c)
inlineinherited

Definition at line 49 of file ModalTheme.h.

◆ setButtonBarHeight()

void ml::ModalSettings::setButtonBarHeight ( float h)
inlineinherited

Definition at line 26 of file ModalSettings.h.

◆ setCancelColor()

void ml::ModalTheme::setCancelColor ( const sf::Color & c)
inlineinherited

Definition at line 48 of file ModalTheme.h.

◆ setCancelLabel()

void ml::Modal::setCancelLabel ( const std::string & label)

Label for the cancel button. Pass empty to show only the confirm button.

◆ setCloseBtnColor()

void ml::ModalTheme::setCloseBtnColor ( const sf::Color & c)
inlineinherited

Definition at line 50 of file ModalTheme.h.

◆ setConfirmColor()

void ml::ModalTheme::setConfirmColor ( const sf::Color & c)
inlineinherited

Definition at line 47 of file ModalTheme.h.

◆ setConfirmLabel()

void ml::Modal::setConfirmLabel ( const std::string & label)

Label for the confirm button. Pass empty to hide the button bar.

◆ setContent()

void ml::Modal::setContent ( ml::Core & content)

Component drawn in the content area. The Modal positions it.

◆ setCornerRadius()

void ml::ModalSettings::setCornerRadius ( float r)
inlineinherited

Definition at line 24 of file ModalSettings.h.

◆ setDisabledColor()

void ml::ControlTheme::setDisabledColor ( const sf::Color & c)
inlineinherited

Definition at line 87 of file ControlTheme.h.

◆ setDisabledTextColor()

void ml::ControlTheme::setDisabledTextColor ( const sf::Color & c)
inlineinherited

Definition at line 88 of file ControlTheme.h.

◆ setDismissOnBackdrop()

void ml::ModalSettings::setDismissOnBackdrop ( bool v)
inlineinherited

Definition at line 27 of file ModalSettings.h.

◆ setErrorColor()

void ml::ControlTheme::setErrorColor ( const sf::Color & c)
inlineinherited

Definition at line 86 of file ControlTheme.h.

◆ setFillColor()

void ml::GraphicTheme::setFillColor ( const sf::Color & c)
inlineinherited

Definition at line 72 of file GraphicTheme.h.

◆ setFocusColor()

void ml::ControlTheme::setFocusColor ( const sf::Color & c)
inlineinherited

Definition at line 85 of file ControlTheme.h.

◆ setFont() [1/2]

void ml::ControlTheme::setFont ( const sf::Font && )
deleteinherited

◆ setFont() [2/2]

void ml::ControlTheme::setFont ( const sf::Font & f)
inlineinherited

Definition at line 92 of file ControlTheme.h.

◆ setFontSize()

void ml::ControlTheme::setFontSize ( unsigned int s)
inlineinherited

Definition at line 94 of file ControlTheme.h.

◆ setFontSizeSmall()

void ml::ControlTheme::setFontSizeSmall ( unsigned int s)
inlineinherited

Definition at line 95 of file ControlTheme.h.

◆ setHoverColor()

void ml::ControlTheme::setHoverColor ( const sf::Color & c)
inlineinherited

Definition at line 84 of file ControlTheme.h.

◆ setModalSize()

void ml::ModalSettings::setModalSize ( const sf::Vector2f & s)
inlineinherited

Definition at line 23 of file ModalSettings.h.

◆ setMutedColor()

void ml::ControlTheme::setMutedColor ( const sf::Color & c)
inlineinherited

Definition at line 90 of file ControlTheme.h.

◆ setOutlineColor()

void ml::GraphicTheme::setOutlineColor ( const sf::Color & c)
inlineinherited

Definition at line 73 of file GraphicTheme.h.

◆ setOutlineThickness()

void ml::GraphicTheme::setOutlineThickness ( float t)
inlineinherited

Definition at line 74 of file GraphicTheme.h.

◆ setPadding()

void ml::ControlTheme::setPadding ( float p)
inlineinherited

Definition at line 91 of file ControlTheme.h.

◆ setPanelColor()

void ml::ModalTheme::setPanelColor ( const sf::Color & c)
inlineinherited

Definition at line 43 of file ModalTheme.h.

◆ setPosition()

void ml::Modal::setPosition ( const sf::Vector2f & pos)
override

◆ setRadius()

void ml::GraphicTheme::setRadius ( float r)
inlineinherited

Definition at line 75 of file GraphicTheme.h.

◆ setSeparatorColor()

void ml::ModalTheme::setSeparatorColor ( const sf::Color & c)
inlineinherited

Definition at line 46 of file ModalTheme.h.

◆ setShowCloseButton()

void ml::ModalSettings::setShowCloseButton ( bool v)
inlineinherited

Definition at line 28 of file ModalSettings.h.

◆ setTextColor()

void ml::ControlTheme::setTextColor ( const sf::Color & c)
inlineinherited

Definition at line 89 of file ControlTheme.h.

◆ setTitle()

void ml::Modal::setTitle ( const std::string & title)

Text displayed in the title bar. Pass an empty string to hide it.

◆ setTitleBarHeight()

void ml::ModalSettings::setTitleBarHeight ( float h)
inlineinherited

Definition at line 25 of file ModalSettings.h.

◆ setTitleTextColor()

void ml::ModalTheme::setTitleTextColor ( const sf::Color & c)
inlineinherited

Definition at line 44 of file ModalTheme.h.

◆ show()

void ml::Modal::show ( )

◆ showImmediate()

void ml::Modal::showImmediate ( )

◆ toggle()

void ml::Modal::toggle ( )

◆ unlockSettings()

void ml::Themeable::unlockSettings ( )
inlineinherited

Allow applySettings() to take effect again.

Definition at line 112 of file Themeable.h.

◆ unlockTheme()

void ml::Themeable::unlockTheme ( )
inlineinherited

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.

Member Data Documentation

◆ backdropColor

sf::Color ml::ModalTheme::backdropColor = sf::Color(0, 0, 0, 160)
inherited

Definition at line 13 of file ModalTheme.h.

◆ bodyTextColor

sf::Color ml::ModalTheme::bodyTextColor = sf::Color(200, 200, 200)
inherited

Definition at line 16 of file ModalTheme.h.

◆ btnTextColor

sf::Color ml::ModalTheme::btnTextColor = sf::Color::White
inherited

Definition at line 20 of file ModalTheme.h.

◆ buttonBarHeight

float ml::ModalSettings::buttonBarHeight = 56.f
inherited

Definition at line 16 of file ModalSettings.h.

◆ cancelColor

sf::Color ml::ModalTheme::cancelColor = sf::Color(70, 70, 70)
inherited

Definition at line 19 of file ModalTheme.h.

◆ closeBtnColor

sf::Color ml::ModalTheme::closeBtnColor = sf::Color(160, 160, 160)
inherited

Definition at line 21 of file ModalTheme.h.

◆ confirmColor

sf::Color ml::ModalTheme::confirmColor = sf::Color(0, 122, 255)
inherited

Definition at line 18 of file ModalTheme.h.

◆ cornerRadius

float ml::ModalSettings::cornerRadius = 12.f
inherited

Definition at line 14 of file ModalSettings.h.

◆ disabledColor

sf::Color ml::ControlTheme::disabledColor = sf::Color(60, 60, 60)
inherited

Definition at line 33 of file ControlTheme.h.

◆ disabledTextColor

sf::Color ml::ControlTheme::disabledTextColor = sf::Color(120, 120, 120)
inherited

Definition at line 34 of file ControlTheme.h.

◆ dismissOnBackdrop

bool ml::ModalSettings::dismissOnBackdrop = true
inherited

Definition at line 17 of file ModalSettings.h.

◆ errorColor

sf::Color ml::ControlTheme::errorColor = sf::Color(220, 70, 70)
inherited

Definition at line 32 of file ControlTheme.h.

◆ fillColor

sf::Color ml::GraphicTheme::fillColor = sf::Color(40, 40, 40)
inherited

Definition at line 43 of file GraphicTheme.h.

◆ focusColor

sf::Color ml::ControlTheme::focusColor = sf::Color(100, 60, 200)
inherited

Definition at line 31 of file ControlTheme.h.

◆ font

const sf::Font* ml::ControlTheme::font = &FontManager<>::getDefault()
inherited

Definition at line 39 of file ControlTheme.h.

◆ fontSize

unsigned int ml::ControlTheme::fontSize = 14
inherited

Definition at line 40 of file ControlTheme.h.

◆ fontSizeSmall

unsigned int ml::ControlTheme::fontSizeSmall = 11
inherited

Definition at line 41 of file ControlTheme.h.

◆ hoverColor

sf::Color ml::ControlTheme::hoverColor = sf::Color(70, 130, 230)
inherited

Definition at line 30 of file ControlTheme.h.

◆ modalSize

sf::Vector2f ml::ModalSettings::modalSize = {420.f, 300.f}
inherited

Definition at line 13 of file ModalSettings.h.

◆ mutedColor

sf::Color ml::ControlTheme::mutedColor = sf::Color(120, 120, 120)
inherited

Definition at line 36 of file ControlTheme.h.

◆ outlineColor

sf::Color ml::GraphicTheme::outlineColor = sf::Color(100, 100, 100)
inherited

Definition at line 44 of file GraphicTheme.h.

◆ outlineThickness

float ml::GraphicTheme::outlineThickness = 1.5f
inherited

Definition at line 45 of file GraphicTheme.h.

◆ padding

float ml::ControlTheme::padding = 8.f
inherited

Definition at line 37 of file ControlTheme.h.

◆ panelColor

sf::Color ml::ModalTheme::panelColor = sf::Color(36, 36, 50)
inherited

Definition at line 14 of file ModalTheme.h.

◆ radius

float ml::GraphicTheme::radius = 8.f
inherited

Definition at line 46 of file GraphicTheme.h.

◆ separatorColor

sf::Color ml::ModalTheme::separatorColor = sf::Color(60, 60, 80)
inherited

Definition at line 17 of file ModalTheme.h.

◆ showCloseButton

bool ml::ModalSettings::showCloseButton = true
inherited

Definition at line 18 of file ModalSettings.h.

◆ textColor

sf::Color ml::ControlTheme::textColor = sf::Color::White
inherited

Definition at line 35 of file ControlTheme.h.

◆ titleBarHeight

float ml::ModalSettings::titleBarHeight = 50.f
inherited

Definition at line 15 of file ModalSettings.h.

◆ titleTextColor

sf::Color ml::ModalTheme::titleTextColor = sf::Color::White
inherited

Definition at line 15 of file ModalTheme.h.


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