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

A horizontal or vertical strip of buttons, separators, and components. More...

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

Inheritance diagram for ml::Toolbar:
[legend]

Public Types

using Flag = ToolbarManifest::Flag
using Orientation = ToolbarSettings::Orientation
using Overflow = ToolbarSettings::Overflow
using State = ToolbarManifest::State

Public Member Functions

 Toolbar (const sf::Font &font=FontManager<>::getDefault())
 Toolbar (const Toolbar &)=delete
void add (const ml::Core &component)
 Const overload — forwards to the non-const add().
void add (ml::Core &component)
 Embed any ml::Core as a positioned toolbar item.
std::size_t addButton (const std::string &label, std::function< void()> action={})
 Add a text-only button. Returns the item index.
void addSeparator ()
 Add a visual separator.
ToolbarThemeapplyFrom (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 clear ()
 Remove all items.
float getBarLength () const
float getBarThickness () const
 height (H) or width (V)
float getContentExtent () const
 Extent of the laid-out items along the bar (width for H, height for V), measured from the bar origin past the last item. Useful for placing sibling controls right after a toolbar whose bar spans the full window.
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.
std::size_t itemCount () const
 Return the number of items (including separators).
void lockSettings ()
 Prevent applySettings() from taking effect.
void lockTheme ()
 Prevent automatic re-styling when the global theme changes.
Toolbaroperator= (const Toolbar &)=delete
void setBarBg (const sf::Color &c)
void setBarLength (float length)
 Override the bar length (width for H, height for V). By default fills the window width.
void setBarPadding (float p)
void setDisabledColor (const sf::Color &c)
void setDisabledTextColor (const sf::Color &c)
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 setItemActiveBg (const sf::Color &c)
void setItemEnabled (std::size_t index, bool enabled)
 Enable or disable an owned button by item index.
void setItemHoverBg (const sf::Color &c)
void setItemLabel (std::size_t index, const std::string &label)
 Update the label of an owned button by item index.
void setItemSelected (std::size_t index, bool selected)
 Set or clear the persistent selected highlight on an owned button.
void setItemSize (sf::Vector2f s)
void setItemSpacing (float s)
void setItemTextColor (const sf::Color &c)
void setMutedColor (const sf::Color &c)
void setOrientation (Orientation o)
void setOutlineColor (const sf::Color &c)
void setOutlineThickness (float t)
void setOverflow (Overflow o)
void setPadding (float p)
void setPosition (const sf::Vector2f &position) override
void setRadius (float r)
void setSeparatorColor (const sf::Color &c)
void setTextColor (const sf::Color &c)
void unlockSettings ()
 Allow applySettings() to take effect again.
void unlockTheme ()
 Resume reacting to global theme changes.

Public Attributes

sf::Color barBg = sf::Color(28, 28, 36)
float barPadding = 4.f
sf::Color disabledColor = sf::Color(60, 60, 60)
sf::Color disabledTextColor = sf::Color(120, 120, 120)
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 itemActiveBg = sf::Color(70, 130, 230, 80)
sf::Color itemHoverBg = sf::Color(255, 255, 255, 20)
sf::Vector2f itemSize = {36.f, 36.f}
 default size for created buttons
float itemSpacing = 2.f
sf::Color itemTextColor = sf::Color::White
 button label color
sf::Color mutedColor = sf::Color(120, 120, 120)
Orientation orientation = Orientation::HORIZONTAL
sf::Color outlineColor = sf::Color(100, 100, 100)
float outlineThickness = 1.5f
Overflow overflow = Overflow::CLIP
float padding = 8.f
float radius = 8.f
sf::Color separatorColor = sf::Color(70, 70, 90)
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 horizontal or vertical strip of buttons, separators, and components.

Items can be added three ways:

Method Result
addButton(label, action) Creates an owned text button
addButton(label, icon, action) Creates an owned icon+label button
addSeparator() Thin visual divider line
add(component) Any external ml::Core — not owned, not resized

All interaction (hover highlight, click) is handled by the toolbar itself. External components added via add() retain their own event subscriptions.

Usage

ml::Toolbar toolbar;
toolbar.setPosition({0.f, 30.f}); // below a MenuBar
toolbar.addButton("New", [&]{ newFile(); });
toolbar.addButton("Open", [&]{ openFile(); });
toolbar.addButton("Save", [&]{ save(); });
toolbar.addSeparator();
toolbar.addButton("Undo", [&]{ undo(); });
toolbar.addButton("Redo", [&]{ redo(); });
toolbar.addSeparator();
// Embed any component as a visual toolbar item.
// add() handles positioning; addComponent() registers it for events.
// Both calls are required for interactive components.
ml::TextInput search;
search.setSize({200.f, 28.f});
search.setPlaceholder("Search...");
toolbar.add(search); // positions in toolbar flow
addComponent(search); // enables click / hover / update events
addComponent(toolbar);
virtual void setSize(const sf::Vector2f &size)
void setPlaceholder(const std::string &text)
A horizontal or vertical strip of buttons, separators, and components.
Definition Toolbar.h:83
void setPosition(const sf::Vector2f &position) override
void add(ml::Core &component)
Embed any ml::Core as a positioned toolbar item.
std::size_t addButton(const std::string &label, std::function< void()> action={})
Add a text-only button. Returns the item index.
void addSeparator()
Add a visual separator.
See also
ToolbarSettings, ToolbarTheme, ToolbarStyle

Definition at line 79 of file Toolbar.h.

Member Typedef Documentation

◆ Flag

Definition at line 85 of file Toolbar.h.

◆ Orientation

◆ Overflow

Definition at line 88 of file Toolbar.h.

◆ State

Definition at line 86 of file Toolbar.h.

Constructor & Destructor Documentation

◆ Toolbar() [1/2]

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

◆ Toolbar() [2/2]

ml::Toolbar::Toolbar ( const Toolbar & )
delete

Member Function Documentation

◆ add() [1/2]

void ml::Toolbar::add ( const ml::Core & component)

Const overload — forwards to the non-const add().

◆ add() [2/2]

void ml::Toolbar::add ( ml::Core & component)

Embed any ml::Core as a positioned toolbar item.

This handles visual placement only — the component is placed in the item flow and repositioned whenever the toolbar moves. It is NOT owned.

To also receive framework events (click, hover, update), you must also register the component with the host's component manager:

toolbar.add(myToggle); // place in toolbar
addComponent(myToggle); // enable events

For display-only items that need no events, add() alone is sufficient.

setEnabled() on the toolbar propagates to all embedded components, including those added via this method.

Parameters
componentAny ml::Core. Not owned — caller manages lifetime.

◆ addButton()

std::size_t ml::Toolbar::addButton ( const std::string & label,
std::function< void()> action = {} )

Add a text-only button. Returns the item index.

◆ addSeparator()

void ml::Toolbar::addSeparator ( )

Add a visual separator.

◆ applyFrom()

ToolbarTheme & ml::ToolbarTheme::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 18 of file ToolbarTheme.h.

◆ applySettings()

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

Definition at line 133 of file Toolbar.h.

◆ applyStyle()

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

Definition at line 150 of file Toolbar.h.

◆ applyTheme()

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

Definition at line 142 of file Toolbar.h.

◆ clear()

void ml::Toolbar::clear ( )

Remove all items.

◆ draw()

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

◆ getBarLength()

float ml::Toolbar::getBarLength ( ) const
inlinenodiscard

Definition at line 217 of file Toolbar.h.

◆ getBarThickness()

float ml::Toolbar::getBarThickness ( ) const
nodiscard

height (H) or width (V)

◆ getContentExtent()

float ml::Toolbar::getContentExtent ( ) const
nodiscard

Extent of the laid-out items along the bar (width for H, height for V), measured from the bar origin past the last item. Useful for placing sibling controls right after a toolbar whose bar spans the full window.

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

◆ itemCount()

std::size_t ml::Toolbar::itemCount ( ) const
inlinenodiscard

Return the number of items (including separators).

Definition at line 208 of file Toolbar.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.

◆ onThemeApplied()

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

Implements ml::Themeable.

◆ operator=()

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

◆ setBarBg()

void ml::ToolbarTheme::setBarBg ( const sf::Color & c)
inlineinherited

Definition at line 36 of file ToolbarTheme.h.

◆ setBarLength()

void ml::Toolbar::setBarLength ( float length)

Override the bar length (width for H, height for V). By default fills the window width.

◆ setBarPadding()

void ml::ToolbarSettings::setBarPadding ( float p)
inlineinherited

Definition at line 31 of file ToolbarSettings.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.

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

◆ setItemActiveBg()

void ml::ToolbarTheme::setItemActiveBg ( const sf::Color & c)
inlineinherited

Definition at line 39 of file ToolbarTheme.h.

◆ setItemEnabled()

void ml::Toolbar::setItemEnabled ( std::size_t index,
bool enabled )

Enable or disable an owned button by item index.

◆ setItemHoverBg()

void ml::ToolbarTheme::setItemHoverBg ( const sf::Color & c)
inlineinherited

Definition at line 38 of file ToolbarTheme.h.

◆ setItemLabel()

void ml::Toolbar::setItemLabel ( std::size_t index,
const std::string & label )

Update the label of an owned button by item index.

◆ setItemSelected()

void ml::Toolbar::setItemSelected ( std::size_t index,
bool selected )

Set or clear the persistent selected highlight on an owned button.

◆ setItemSize()

void ml::ToolbarSettings::setItemSize ( sf::Vector2f s)
inlineinherited

Definition at line 29 of file ToolbarSettings.h.

◆ setItemSpacing()

void ml::ToolbarSettings::setItemSpacing ( float s)
inlineinherited

Definition at line 30 of file ToolbarSettings.h.

◆ setItemTextColor()

void ml::ToolbarTheme::setItemTextColor ( const sf::Color & c)
inlineinherited

Definition at line 40 of file ToolbarTheme.h.

◆ setMutedColor()

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

Definition at line 90 of file ControlTheme.h.

◆ setOrientation()

void ml::ToolbarSettings::setOrientation ( Orientation o)
inlineinherited

Definition at line 27 of file ToolbarSettings.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.

◆ setOverflow()

void ml::ToolbarSettings::setOverflow ( Overflow o)
inlineinherited

Definition at line 28 of file ToolbarSettings.h.

◆ setPadding()

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

Definition at line 91 of file ControlTheme.h.

◆ setPosition()

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

◆ setRadius()

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

Definition at line 75 of file GraphicTheme.h.

◆ setSeparatorColor()

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

Definition at line 37 of file ToolbarTheme.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

◆ barBg

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

Definition at line 12 of file ToolbarTheme.h.

◆ barPadding

float ml::ToolbarSettings::barPadding = 4.f
inherited

Definition at line 20 of file ToolbarSettings.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.

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

◆ itemActiveBg

sf::Color ml::ToolbarTheme::itemActiveBg = sf::Color(70, 130, 230, 80)
inherited

Definition at line 15 of file ToolbarTheme.h.

◆ itemHoverBg

sf::Color ml::ToolbarTheme::itemHoverBg = sf::Color(255, 255, 255, 20)
inherited

Definition at line 14 of file ToolbarTheme.h.

◆ itemSize

sf::Vector2f ml::ToolbarSettings::itemSize = {36.f, 36.f}
inherited

default size for created buttons

Definition at line 18 of file ToolbarSettings.h.

◆ itemSpacing

float ml::ToolbarSettings::itemSpacing = 2.f
inherited

Definition at line 19 of file ToolbarSettings.h.

◆ itemTextColor

sf::Color ml::ToolbarTheme::itemTextColor = sf::Color::White
inherited

button label color

Definition at line 16 of file ToolbarTheme.h.

◆ mutedColor

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

Definition at line 36 of file ControlTheme.h.

◆ orientation

Orientation ml::ToolbarSettings::orientation = Orientation::HORIZONTAL
inherited

Definition at line 16 of file ToolbarSettings.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.

◆ overflow

Overflow ml::ToolbarSettings::overflow = Overflow::CLIP
inherited

Definition at line 17 of file ToolbarSettings.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::ToolbarTheme::separatorColor = sf::Color(70, 70, 90)
inherited

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