ml::docs | Your First App Manifests Events Messaging Plugins Scenes Resources
See all tutorials →
Beginner 4 sections ~8 min C++17/20

Disclosure & Grouping

Accordions, toggle groups and the native OS menu bar — for organising what the user does not need to see all at once.

Introduction

Three Controls

Three controls for organising things the user does not need to see all at once.

ControlGroups
AccordionSections of content that expand and collapse
ToggleGroupToggles that behave as one selection
NativeMenuBarCommands, in the operating system's own menu bar
1Sections

Accordion

An accordion holds labelled sections. addSection returns references to the header and the content area, so you fill the section rather than handing it a widget.

ml::Accordion panel;

auto [header, list] = panel.addSection("Students", 180.f);
list.addItem("Amelia Adamczewski");
list.addItem("Samir Chaudhry");

panel.onSectionChanged([](std::size_t index, bool expanded){
    if (expanded) loadSectionData(index);
});
MethodEffect
addSection(label, height)Add a section; returns header and content refs.
removeSection(index)Remove by position.
onSectionChanged(cb)Index plus whether it is now expanded.
onSectionChanged is the right place to load a section's data. Populating every section up front costs work the user may never look at — expanding is the signal that they want it.
2Selection

ToggleGroup

ToggleGroup makes several independent toggles behave as one control, keyed by string.

ml::ToggleGroup view;
view.add(listToggle, "list");
view.add(gridToggle, "grid");
view.setOn("grid", true);

if (view.isOn("grid")) layoutAsGrid();
MethodEffect
add(toggle, key)Adopt a PillToggle, SegmentToggle or ButtonToggle.
setOn(key, bool)Set one member's state.
isOn(key)Query by key.
clearToggles()Release every member.
Keys, not indices. A group referenced by position breaks the moment you reorder the toggles or add one in the middle — the string survives both.
3Platform

NativeMenuBar

NativeMenuBar builds a real operating-system menu: the global menu bar on macOS, an HMENU on Windows.

ml::NativeMenuBar menu;
// ... describe menus and items ...
menu.attach();     // macOS: global menu bar. Windows: attached to the SFML window.
MethodEffect
attach()Install the menu. A no-op on unsupported platforms.
detach()Remove it.
attach() being a no-op elsewhere is deliberate — you can call it unconditionally and let platforms without a native menu bar ignore it. Do not put commands only in the native menu, though: on those platforms they would be unreachable. Mirror anything essential in your own UI.