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

A vertically stacked set of collapsible sections. More...

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

Inheritance diagram for ml::Accordion:
[legend]

Classes

struct  SectionRef

Public Types

using Flag = AccordionManifest::Flag
using State = AccordionManifest::State

Public Member Functions

 Accordion (const Accordion &)=delete
 Accordion (const sf::Font &font=FontManager<>::getDefault())
SectionRef addSection (const std::string &label, float contentHeight=120.f)
 Add a section, creating its ListItem header and List content.
AccordionThemeapplyFrom (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 collapse (std::size_t index)
 Collapse a section by index.
void expand (std::size_t index)
 Expand a section by index. Collapses others if exclusive.
sf::Color getChevronColor () const
float getChevronSize () const
sf::Color getContentBg () const
sf::Color getDisabledColor () const
sf::Color getDisabledTextColor () const
sf::Color getDividerColor () const
sf::Color getErrorColor () const
bool getExclusive () 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 getHeaderBg () const
float getHeaderHeight () const
sf::Color getHeaderHovered () const
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
float getTotalHeight () const
float getWidth () const
bool isExpanded (std::size_t index) const
 Return whether a section is expanded.
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.
void onSectionChanged (std::function< void(std::size_t index, bool expanded)> cb)
 Fired when a section is expanded or collapsed.
Accordionoperator= (const Accordion &)=delete
void removeSection (std::size_t index)
 Remove a section by index.
std::size_t sectionCount () const
 Return the number of sections.
void setChevronColor (const sf::Color &c)
void setChevronSize (float s)
void setContentBg (const sf::Color &c)
void setDisabledColor (const sf::Color &c)
void setDisabledTextColor (const sf::Color &c)
void setDividerColor (const sf::Color &c)
void setErrorColor (const sf::Color &c)
void setExclusive (bool e)
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 setHeaderBg (const sf::Color &c)
void setHeaderHeight (float h)
void setHeaderHovered (const sf::Color &c)
void setHoverColor (const sf::Color &c)
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 setSize (const sf::Vector2f &size)
void setTextColor (const sf::Color &c)
void setWidth (float width)
void toggle (std::size_t index)
 Toggle a section's expanded state.
void unlockSettings ()
 Allow applySettings() to take effect again.
void unlockTheme ()
 Resume reacting to global theme changes.

Public Attributes

sf::Color chevronColor = sf::Color(180, 180, 180)
float chevronRight = 14.f
 Right margin for the chevron.
float chevronSize = 8.f
sf::Color contentBg = sf::Color(30, 30, 30)
sf::Color disabledColor = sf::Color(60, 60, 60)
sf::Color disabledTextColor = sf::Color(120, 120, 120)
sf::Color dividerColor = sf::Color(70, 70, 70)
sf::Color errorColor = sf::Color(220, 70, 70)
bool exclusive = true
 Only one section open at a time.
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 headerBg = sf::Color(45, 45, 45)
float headerHeight = 40.f
sf::Color headerHovered = sf::Color(60, 60, 60)
sf::Color hoverColor = sf::Color(70, 130, 230)
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 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 vertically stacked set of collapsible sections.

Each section has a ListItem header and an owned List that is shown or hidden when the header is clicked. By default only one section can be open at a time (exclusive = true).

The accordion creates and owns both the header and list — addSection returns references to both so the caller can configure them freely.

Usage

ml::Accordion accordion;
accordion.setWidth(400.f);
accordion.setPosition({40.f, 100.f});
auto [header, list] = accordion.addSection("Students", 180.f);
header.setDescription("3 enrolled");
list.addItem("Alice");
list.addItem("Bob");
accordion.onSectionChanged([](std::size_t i, bool expanded){});
addComponent(accordion);
A vertically stacked set of collapsible sections.
Definition Accordion.h:65
void onSectionChanged(std::function< void(std::size_t index, bool expanded)> cb)
Fired when a section is expanded or collapsed.
SectionRef addSection(const std::string &label, float contentHeight=120.f)
Add a section, creating its ListItem header and List content.
void setWidth(float width)
void setPosition(const sf::Vector2f &position) override
See also
AccordionSettings, AccordionTheme, ListItem, List

Definition at line 61 of file Accordion.h.

Member Typedef Documentation

◆ Flag

Definition at line 67 of file Accordion.h.

◆ State

Definition at line 68 of file Accordion.h.

Constructor & Destructor Documentation

◆ Accordion() [1/2]

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

◆ Accordion() [2/2]

ml::Accordion::Accordion ( const Accordion & )
delete

Member Function Documentation

◆ addSection()

SectionRef ml::Accordion::addSection ( const std::string & label,
float contentHeight = 120.f )

Add a section, creating its ListItem header and List content.

Parameters
labelHeader label text.
contentHeightHeight of the list area when the section is expanded.
Returns
References to the created header and list for further configuration.
auto [header, list] = accordion.addSection("Students", 180.f);
header.setDescription("3 enrolled");
list.addItem("Alice");

◆ applyFrom()

AccordionTheme & ml::AccordionTheme::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::GraphicTheme.

Definition at line 20 of file AccordionTheme.h.

◆ applySettings()

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

Definition at line 109 of file Accordion.h.

◆ applyStyle()

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

Definition at line 126 of file Accordion.h.

◆ applyTheme()

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

Definition at line 118 of file Accordion.h.

◆ collapse()

void ml::Accordion::collapse ( std::size_t index)

Collapse a section by index.

◆ draw()

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

◆ expand()

void ml::Accordion::expand ( std::size_t index)

Expand a section by index. Collapses others if exclusive.

◆ getChevronColor()

sf::Color ml::AccordionTheme::getChevronColor ( ) const
inlinenodiscardinherited

Definition at line 40 of file AccordionTheme.h.

◆ getChevronSize()

float ml::AccordionSettings::getChevronSize ( ) const
inlinenodiscardinherited

Definition at line 26 of file AccordionSettings.h.

◆ getContentBg()

sf::Color ml::AccordionTheme::getContentBg ( ) const
inlinenodiscardinherited

Definition at line 39 of file AccordionTheme.h.

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

◆ getDividerColor()

sf::Color ml::AccordionTheme::getDividerColor ( ) const
inlinenodiscardinherited

Definition at line 41 of file AccordionTheme.h.

◆ getErrorColor()

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

Definition at line 74 of file ControlTheme.h.

◆ getExclusive()

bool ml::AccordionSettings::getExclusive ( ) const
inlinenodiscardinherited

Definition at line 27 of file AccordionSettings.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::Accordion::getGlobalBounds ( ) const
override

◆ getHeaderBg()

sf::Color ml::AccordionTheme::getHeaderBg ( ) const
inlinenodiscardinherited

Definition at line 37 of file AccordionTheme.h.

◆ getHeaderHeight()

float ml::AccordionSettings::getHeaderHeight ( ) const
inlinenodiscardinherited

Definition at line 25 of file AccordionSettings.h.

◆ getHeaderHovered()

sf::Color ml::AccordionTheme::getHeaderHovered ( ) const
inlinenodiscardinherited

Definition at line 38 of file AccordionTheme.h.

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

◆ getTotalHeight()

float ml::Accordion::getTotalHeight ( ) const
nodiscard

◆ getWidth()

float ml::Accordion::getWidth ( ) const
inlinenodiscard

Definition at line 178 of file Accordion.h.

◆ isExpanded()

bool ml::Accordion::isExpanded ( std::size_t index) const
nodiscard

Return whether a section is expanded.

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

◆ onSectionChanged()

void ml::Accordion::onSectionChanged ( std::function< void(std::size_t index, bool expanded)> cb)

Fired when a section is expanded or collapsed.

◆ onThemeApplied()

void ml::Accordion::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=()

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

◆ removeSection()

void ml::Accordion::removeSection ( std::size_t index)

Remove a section by index.

◆ sectionCount()

std::size_t ml::Accordion::sectionCount ( ) const
inlinenodiscard

Return the number of sections.

Definition at line 169 of file Accordion.h.

◆ setChevronColor()

void ml::AccordionTheme::setChevronColor ( const sf::Color & c)
inlineinherited

Definition at line 46 of file AccordionTheme.h.

◆ setChevronSize()

void ml::AccordionSettings::setChevronSize ( float s)
inlineinherited

Definition at line 30 of file AccordionSettings.h.

◆ setContentBg()

void ml::AccordionTheme::setContentBg ( const sf::Color & c)
inlineinherited

Definition at line 45 of file AccordionTheme.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.

◆ setDividerColor()

void ml::AccordionTheme::setDividerColor ( const sf::Color & c)
inlineinherited

Definition at line 47 of file AccordionTheme.h.

◆ setErrorColor()

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

Definition at line 86 of file ControlTheme.h.

◆ setExclusive()

void ml::AccordionSettings::setExclusive ( bool e)
inlineinherited

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

◆ setHeaderBg()

void ml::AccordionTheme::setHeaderBg ( const sf::Color & c)
inlineinherited

Definition at line 43 of file AccordionTheme.h.

◆ setHeaderHeight()

void ml::AccordionSettings::setHeaderHeight ( float h)
inlineinherited

Definition at line 29 of file AccordionSettings.h.

◆ setHeaderHovered()

void ml::AccordionTheme::setHeaderHovered ( const sf::Color & c)
inlineinherited

Definition at line 44 of file AccordionTheme.h.

◆ setHoverColor()

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

Definition at line 84 of file ControlTheme.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.

◆ setPosition()

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

◆ setRadius()

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

Definition at line 75 of file GraphicTheme.h.

◆ setSize()

void ml::Accordion::setSize ( const sf::Vector2f & size)
inline

Definition at line 177 of file Accordion.h.

◆ setTextColor()

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

Definition at line 89 of file ControlTheme.h.

◆ setWidth()

void ml::Accordion::setWidth ( float width)

◆ toggle()

void ml::Accordion::toggle ( std::size_t index)

Toggle a section's expanded state.

◆ 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

◆ chevronColor

sf::Color ml::AccordionTheme::chevronColor = sf::Color(180, 180, 180)
inherited

Definition at line 17 of file AccordionTheme.h.

◆ chevronRight

float ml::AccordionSettings::chevronRight = 14.f
inherited

Right margin for the chevron.

Definition at line 16 of file AccordionSettings.h.

◆ chevronSize

float ml::AccordionSettings::chevronSize = 8.f
inherited

Definition at line 15 of file AccordionSettings.h.

◆ contentBg

sf::Color ml::AccordionTheme::contentBg = sf::Color(30, 30, 30)
inherited

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

◆ dividerColor

sf::Color ml::AccordionTheme::dividerColor = sf::Color(70, 70, 70)
inherited

Definition at line 18 of file AccordionTheme.h.

◆ errorColor

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

Definition at line 32 of file ControlTheme.h.

◆ exclusive

bool ml::AccordionSettings::exclusive = true
inherited

Only one section open at a time.

Definition at line 17 of file AccordionSettings.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.

◆ headerBg

sf::Color ml::AccordionTheme::headerBg = sf::Color(45, 45, 45)
inherited

Definition at line 14 of file AccordionTheme.h.

◆ headerHeight

float ml::AccordionSettings::headerHeight = 40.f
inherited

Definition at line 14 of file AccordionSettings.h.

◆ headerHovered

sf::Color ml::AccordionTheme::headerHovered = sf::Color(60, 60, 60)
inherited

Definition at line 15 of file AccordionTheme.h.

◆ hoverColor

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

Definition at line 30 of file ControlTheme.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.

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