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

A desktop-style horizontal menu bar with dropdown panels. More...

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

Inheritance diagram for ml::MenuBar:
[legend]

Public Types

using Flag = MenuBarManifest::Flag
using State = MenuBarManifest::State

Public Member Functions

 MenuBar (const MenuBar &)=delete
 MenuBar (const sf::Font &font=FontManager<>::getDefault())
void addMenu (const std::string &label, std::vector< MenuItem > items)
 Add a top-level menu entry with its dropdown items.
MenuBarThemeapplyFrom (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)
void closeMenus ()
 Close all open dropdowns programmatically.
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
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.
std::size_t menuCount () const
 Return the number of top-level menu entries.
MenuBaroperator= (const MenuBar &)=delete
void setAutoFillWidth (bool b)
void setBarHeight (float h)
void setDisabledColor (const sf::Color &c)
void setDisabledTextColor (const sf::Color &c)
void setDropdownItemH (float h)
void setDropdownMinW (float w)
void setEntryPadding (float p)
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 setItemChecked (std::size_t menuIndex, std::size_t itemIndex, bool checked)
 Set checked state on a specific item.
void setItemEnabled (std::size_t menuIndex, std::size_t itemIndex, bool enabled)
 Enable or disable a specific item.
void setMenuItems (std::size_t menuIndex, std::vector< MenuItem > items)
 Replace the items of an existing menu by index.
void setMutedColor (const sf::Color &c)
void setOutlineColor (const sf::Color &c)
void setOutlineThickness (float t)
void setPadding (float p)
void setPosition (const sf::Vector2f &position) override
void setRadius (float r)
void setTextColor (const sf::Color &c)
void unlockSettings ()
 Allow applySettings() to take effect again.
void unlockTheme ()
 Resume reacting to global theme changes.

Public Attributes

bool autoFillWidth = true
sf::Color barBg = sf::Color(28, 28, 36)
float barHeight = 30.f
sf::Color checkmarkColor = sf::Color(70, 130, 230)
sf::Color disabledColor = sf::Color(60, 60, 60)
sf::Color disabledTextColor = sf::Color(120, 120, 120)
sf::Color dropdownBg = sf::Color(35, 35, 45)
sf::Color dropdownBorder = sf::Color(70, 70, 90)
float dropdownBorderThk = 1.f
float dropdownItemH = 28.f
 height of each dropdown row
float dropdownMinW = 180.f
sf::Color entryHoverBg = sf::Color(255, 255, 255, 20)
sf::Color entryOpenBg = sf::Color(255, 255, 255, 30)
float entryPadding = 14.f
 horizontal padding per entry label
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::Color itemDisabledColor = sf::Color(100, 100, 120)
sf::Color itemHoverBg = sf::Color(70, 130, 230, 60)
float leftInset = 0.f
 extra space reserved on the left before entries
sf::Color mutedColor = sf::Color(120, 120, 120)
sf::Color outlineColor = sf::Color(100, 100, 100)
float outlineThickness = 1.5f
float padding = 8.f
float radius = 8.f
sf::Color separatorColor = sf::Color(70, 70, 90)
sf::Color shortcutColor = sf::Color(140, 140, 160)
sf::Color textColor = 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 desktop-style horizontal menu bar with dropdown panels.

MenuBar auto-fills the window width and sits at y=0 by default. Each top-level entry opens a dropdown containing MenuItem rows that support labels, shortcuts, icons, checkmarks, separators, and submenus.

Usage

bar.addMenu("File", {
ml::MenuItem::item("New", [&]{ newFile(); }, "Ctrl+N"),
ml::MenuItem::item("Open", [&]{ openFile(); }, "Ctrl+O"),
ml::MenuItem::item("Save", [&]{ save(); }, "Ctrl+S"),
});
bar.addMenu("Edit", {
ml::MenuItem::item("Undo", [&]{ undo(); }, "Ctrl+Z"),
ml::MenuItem::chk("Word wrap", wordWrap),
ml::MenuItem::sub("Encoding", {
ml::MenuItem::item("Latin-1"),
}),
});
addComponent(bar);
A desktop-style horizontal menu bar with dropdown panels.
Definition MenuBar.h:79
void addMenu(const std::string &label, std::vector< MenuItem > items)
Add a top-level menu entry with its dropdown items.
static MenuItem chk(const std::string &label, bool &ref, std::function< void()> onChange={})
Checkable item that toggles a bool reference.
Definition MenuItem.h:76
static MenuItem sep()
Horizontal divider line.
Definition MenuItem.h:101
static MenuItem item(const std::string &label, std::function< void()> action={}, const std::string &shortcut="", const sf::Texture *icon=nullptr)
Standard clickable item.
Definition MenuItem.h:62
static MenuItem sub(const std::string &label, std::vector< MenuItem > items)
Item that opens a submenu.
Definition MenuItem.h:91
See also
MenuItem, MenuBarSettings, MenuBarTheme, MenuBarStyle

Definition at line 75 of file MenuBar.h.

Member Typedef Documentation

◆ Flag

Definition at line 81 of file MenuBar.h.

◆ State

Definition at line 82 of file MenuBar.h.

Constructor & Destructor Documentation

◆ MenuBar() [1/2]

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

◆ MenuBar() [2/2]

ml::MenuBar::MenuBar ( const MenuBar & )
delete

Member Function Documentation

◆ addMenu()

void ml::MenuBar::addMenu ( const std::string & label,
std::vector< MenuItem > items )

Add a top-level menu entry with its dropdown items.

◆ applyFrom()

MenuBarTheme & ml::MenuBarTheme::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 MenuBarTheme.h.

◆ applySettings()

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

Definition at line 152 of file MenuBar.h.

◆ applyStyle()

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

Definition at line 169 of file MenuBar.h.

◆ applyTheme()

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

Definition at line 161 of file MenuBar.h.

◆ closeMenus()

void ml::MenuBar::closeMenus ( )

Close all open dropdowns programmatically.

◆ draw()

void ml::MenuBar::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::MenuBar::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::MenuBar::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.

◆ 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.

◆ 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.

◆ menuCount()

std::size_t ml::MenuBar::menuCount ( ) const
inlinenodiscard

Return the number of top-level menu entries.

Definition at line 197 of file MenuBar.h.

◆ onThemeApplied()

void ml::MenuBar::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.

◆ operator=()

MenuBar & ml::MenuBar::operator= ( const MenuBar & )
delete

◆ setAutoFillWidth()

void ml::MenuBarSettings::setAutoFillWidth ( bool b)
inlineinherited

Definition at line 29 of file MenuBarSettings.h.

◆ setBarHeight()

void ml::MenuBarSettings::setBarHeight ( float h)
inlineinherited

Definition at line 25 of file MenuBarSettings.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.

◆ setDropdownItemH()

void ml::MenuBarSettings::setDropdownItemH ( float h)
inlineinherited

Definition at line 27 of file MenuBarSettings.h.

◆ setDropdownMinW()

void ml::MenuBarSettings::setDropdownMinW ( float w)
inlineinherited

Definition at line 28 of file MenuBarSettings.h.

◆ setEntryPadding()

void ml::MenuBarSettings::setEntryPadding ( float p)
inlineinherited

Definition at line 26 of file MenuBarSettings.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.

◆ setItemChecked()

void ml::MenuBar::setItemChecked ( std::size_t menuIndex,
std::size_t itemIndex,
bool checked )

Set checked state on a specific item.

◆ setItemEnabled()

void ml::MenuBar::setItemEnabled ( std::size_t menuIndex,
std::size_t itemIndex,
bool enabled )

Enable or disable a specific item.

◆ setMenuItems()

void ml::MenuBar::setMenuItems ( std::size_t menuIndex,
std::vector< MenuItem > items )

Replace the items of an existing menu by index.

◆ 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.

◆ setPosition()

void ml::MenuBar::setPosition ( const sf::Vector2f & position)
override

◆ setRadius()

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

Definition at line 75 of file GraphicTheme.h.

◆ setTextColor()

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

Definition at line 89 of file ControlTheme.h.

◆ 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

◆ autoFillWidth

bool ml::MenuBarSettings::autoFillWidth = true
inherited

Definition at line 18 of file MenuBarSettings.h.

◆ barBg

sf::Color ml::MenuBarTheme::barBg = sf::Color(28, 28, 36)
inherited

Definition at line 12 of file MenuBarTheme.h.

◆ barHeight

float ml::MenuBarSettings::barHeight = 30.f
inherited

Definition at line 12 of file MenuBarSettings.h.

◆ checkmarkColor

sf::Color ml::MenuBarTheme::checkmarkColor = sf::Color(70, 130, 230)
inherited

Definition at line 19 of file MenuBarTheme.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.

◆ dropdownBg

sf::Color ml::MenuBarTheme::dropdownBg = sf::Color(35, 35, 45)
inherited

Definition at line 15 of file MenuBarTheme.h.

◆ dropdownBorder

sf::Color ml::MenuBarTheme::dropdownBorder = sf::Color(70, 70, 90)
inherited

Definition at line 16 of file MenuBarTheme.h.

◆ dropdownBorderThk

float ml::MenuBarSettings::dropdownBorderThk = 1.f
inherited

Definition at line 17 of file MenuBarSettings.h.

◆ dropdownItemH

float ml::MenuBarSettings::dropdownItemH = 28.f
inherited

height of each dropdown row

Definition at line 15 of file MenuBarSettings.h.

◆ dropdownMinW

float ml::MenuBarSettings::dropdownMinW = 180.f
inherited

Definition at line 16 of file MenuBarSettings.h.

◆ entryHoverBg

sf::Color ml::MenuBarTheme::entryHoverBg = sf::Color(255, 255, 255, 20)
inherited

Definition at line 13 of file MenuBarTheme.h.

◆ entryOpenBg

sf::Color ml::MenuBarTheme::entryOpenBg = sf::Color(255, 255, 255, 30)
inherited

Definition at line 14 of file MenuBarTheme.h.

◆ entryPadding

float ml::MenuBarSettings::entryPadding = 14.f
inherited

horizontal padding per entry label

Definition at line 13 of file MenuBarSettings.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.

◆ itemDisabledColor

sf::Color ml::MenuBarTheme::itemDisabledColor = sf::Color(100, 100, 120)
inherited

Definition at line 21 of file MenuBarTheme.h.

◆ itemHoverBg

sf::Color ml::MenuBarTheme::itemHoverBg = sf::Color(70, 130, 230, 60)
inherited

Definition at line 20 of file MenuBarTheme.h.

◆ leftInset

float ml::MenuBarSettings::leftInset = 0.f
inherited

extra space reserved on the left before entries

Definition at line 14 of file MenuBarSettings.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.

◆ radius

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

Definition at line 46 of file GraphicTheme.h.

◆ separatorColor

sf::Color ml::MenuBarTheme::separatorColor = sf::Color(70, 70, 90)
inherited

Definition at line 17 of file MenuBarTheme.h.

◆ shortcutColor

sf::Color ml::MenuBarTheme::shortcutColor = sf::Color(140, 140, 160)
inherited

Definition at line 18 of file MenuBarTheme.h.

◆ textColor

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

Definition at line 35 of file ControlTheme.h.


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