Skip to content

Accordion

A list of sections, each a title that shows or hides its content when clicked, or with Space or Enter while focused. Opening one closes the one that was open; clicking the open one closes it. All start closed, and the framework keeps which is open.

ui.accordion

Basic

ui.column().w(320).children(|ui| {
ui.accordion().default_open(0).children(|a| {
a.item("Is it free?").children(|ui| {
ui.text("Yes, under the Apache 2.0 license.").muted();
});
a.item("Does it need a GPU?").children(|ui| {
ui.text("No. Everything is drawn on the CPU.").muted();
});
a.item("Which platforms?").children(|ui| {
ui.text("macOS, Windows and Linux.").muted();
});
});
});

Several open at once

ui.column().w(320).children(|ui| {
ui.accordion().multiple().default_open(1).children(|a| {
a.item("Appearance").children(|ui| {
ui.text("Follows the system.").muted();
});
a.item("Language").children(|ui| {
ui.text("English").muted();
});
});
});

API reference

SettingDescription
.multiple()Lets several sections be open at once: each opens and closes on its own.
.value(value: &'u mut Option<usize>)Keeps which section is open in value, as its position from 0, or None for none: the application can read it and set it. Without this the framework keeps it. It has no effect when several sections may be open.
.default_open(index: usize)The section that is open the first time the accordion appears, as its position from 0.
.children(f: impl FnOnce(&mut AccordionUi<'_, 'a>)Places the accordion; f declares its sections with AccordionUi::item. Returns the result of f.