iced-cube

Forms

Switch

Turns a setting on or off with immediate effect.

use iced_cube::switch;
API reference
Settings list: Switches in a settings list, one depending on another.Settings list: Switches in a settings list, one depending on another.
Static preview
Settings list. Switches in a settings list, one depending on another.

Usage

Use a switch for settings that apply as soon as they change, such as turning notifications on. For choices that wait for a submit button, use a checkbox.

In a settings list, pass the switch without a label and put the title and description in your own layout, as the settings example does.

Examples

Default

A labelled switch bound to a bool.

Default: A labelled switch bound to a bool.Default: A labelled switch bound to a bool.
Static preview

States

On and off, enabled and disabled.

States: On and off, enabled and disabled.States: On and off, enabled and disabled.
Static preview

API

ItemDescription
switch(is_on)Creates a switch. It renders disabled until it has a message.
.label(text)Adds a label after the switch. Clicking the label toggles the switch too.
.on_toggle(f) / .on_toggle_maybe(option)Sets the message for a click. The closure gets the new value. None disables the switch.
switch::default_keymap()The default shortcuts as a Keymap<Action>, for apps that track a current switch.
Action::Toggle.apply(is_on)The value a click would send. Pass it to your on_toggle message.

Keyboard

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

KeysAction
SpaceToggle Turns the current switch on or off.
Esc