iced-cube

Forms

Slider

Chooses a number within a range by dragging a handle.

use iced_cube::slider;
API reference
Default: A labelled slider that shows its value.Default: A labelled slider that shows its value.
Static preview
Default. A labelled slider that shows its value.

Usage

Sliders work with f32, f64, u8, u16, u32, i16 and i32: any Copy number that converts from u8 and into f64 without loss. That rules out i8, 64-bit integers and usize.

Use sliders where an approximate value is fine, such as volume or opacity. When the exact number matters, show the value with .show_value() or .format_value(f).

iced sliders do not take keyboard focus, so shortcuts are app-wide. With several sliders on screen, the app decides which one is current and applies the resolved action to that value.

Examples

Steps

Snapping to a step, with a custom value format.

Steps: Snapping to a step, with a custom value format.Steps: Snapping to a step, with a custom value format.
Static preview

Keyboard shortcuts

Arrow keys, Home and End through the default keymap, plus an added binding.

Keyboard shortcuts: Arrow keys, Home and End through the default keymap, plus an added binding.Keyboard shortcuts: Arrow keys, Home and End through the default keymap, plus an added binding.
Static preview

Disabled

A slider without a message renders disabled.

Disabled: A slider without a message renders disabled.Disabled: A slider without a message renders disabled.
Static preview

API

ItemDescription
slider(range, value)Creates a slider over an inclusive range. The value is clamped to the range. It renders disabled until it has a message.
.on_change(f)Sets the message emitted with the new value while dragging.
.on_release(message)Sets a message emitted once the handle is released, useful for saving the final value.
.step(value)Snaps the value to multiples of the step. Zero or negative steps are ignored.
.label(text)Shows a label above the slider.
.show_value() / .format_value(f)Shows the current value above the slider, as plain text or formatted by a closure.
.width(length)Overrides the width. Sliders fill the available width by default.
slider::default_keymap()The default shortcuts as a Keymap<Action>. Bind, unbind or clear chords to change them.
action.apply(value, range, step)The value after an Action (Increase, Decrease, Min or Max), snapped to the step grid. Send it through your on_change message.
slider::stepped(value, range, step, steps)Moves a value by whole steps within a range. Without a valid step it moves by 1, as dragging does.

Keyboard

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

KeysAction
ArrowRight or ArrowUpIncrease Raises the value by one step.
ArrowLeft or ArrowDownDecrease Lowers the value by one step.
HomeMin Sets the value to the start of the range.
EndMax Sets the value to the end of the range.
Esc