iced-cube

Layout

Accordion

Stacked sections that expand and collapse under their headers.

use iced_cube::layout::accordion::{self, Mode, accordion};
API reference
Single: Opening a section closes the others.Single: Opening a section closes the others.
Static preview
Single. Opening a section closes the others.

Usage

Use an accordion to shorten long pages such as FAQs or settings, where people only need one or two sections at a time. The chevron points down while a section is closed and up while it is open.

Semibold headings separate each section from its muted body text. Content inherits the muted colour by default; text and controls with their own styles keep those colours.

Clicking the header of an open section closes it in both modes.

The state does not know which sections exist, so keyboard actions take the section ids in display order. Next and Previous move the most recently opened section along that list, and ExpandAll only applies in Multiple mode.

Examples

Multiple

Sections open and close independently.

Multiple: Sections open and close independently.Multiple: Sections open and close independently.
Static preview

API

ItemDescription
State::new(Mode)Starts with every section closed. Single keeps at most one open; Multiple opens each independently.
.with_open(id)Starts with a section open.
state.update(Event)Toggle(id), Open(id) or Close(id). Returns Opened(id) or Closed(id) when something changed.
state.is_open(id) / state.open()Checks one section, or lists the open ones in the order they opened.
state.set_mode(Mode)Switches mode. Going to Single keeps only the first open section.
accordion(&state)Renders the sections. Headers render disabled until .on_event is set.
.item(id, title, content)Adds a section. Closed sections are not laid out or drawn, but their content is still built on every view, so check state.is_open(id) first if it is expensive.
state.mode()The current Mode.
.on_event(f)Maps accordion events to your message.
accordion::default_keymap()The default shortcuts as a Keymap<Action>. Bind, unbind or clear chords to change them.
action.events(&state, &sections)The events for a resolved Action, given every section id in display order. Pass each one to state.update.

Keyboard

Default shortcuts. Every one can be changed or removed with a keymap; see Keyboard shortcuts.

KeysAction
ArrowDownNext Opens the next section in place of the current one, wrapping at the end.
ArrowUpPrevious Opens the previous section in place of the current one, wrapping at the start.
Ctrl+Shift+ArrowDownExpandAll Opens every section. Only applies when several may be open.
Ctrl+Shift+ArrowUpCollapseAll Closes every open section.
Esc