Skip to main content

centered_slider

Function centered_slider 

Source
pub fn centered_slider() -> CenteredSliderBuilder
Expand description

§centered_slider

Adjust a value around a neutral midpoint for balance and deviation settings.

§Usage

Use for adjustments that have a neutral midpoint, such as balance controls or deviation settings.

Arrow keys move one step. Home and End select the allowed bounds, and PageUp and PageDown move up to ten steps. Continuous sliders use 1% keyboard steps.

Supplied values are clamped to 0–1 and, for discrete sliders, rounded to the nearest tick. Ties round upward and NaN resolves to zero. This normalization does not call on_change or modify caller-owned state.

§Parameters

  • modifier — slider placement and size constraints.

  • value, on_change — controlled fraction and change callback.

  • orientation, reverse_direction — physical axis and increasing-value direction.

  • size, thumb_diameter — track size and handle width.

  • active_track_color, inactive_track_color, thumb_color — optional colors.

  • active_tick_color, inactive_tick_color — optional tick foregrounds; inactive tick color also applies to end stops.

  • disabled — whether pointer, keyboard, and accessibility input are disabled.

  • accessibility_label, accessibility_description — accessible control name and details.

  • show_stop_indicator, steps — end stops and the number of intermediate steps.

  • inset_icon — optional leading icon for larger size variants.

  • controller — optional shared focus and drag state.

  • presentation_state — optional visual interaction without changing focus or gestures.

  • value_indicator — hidden by default; show while focused/dragging or always. Pass the host received from slider_value_indicator_provider.

  • value_indicator_host — overlay target received from the provider slot.

  • value_label — optional formatted value for the floating label and screen reader; defaults to a rounded percentage without a percent sign when labels are enabled.

§Examples

use tessera_components::modifier::ModifierExt as _;
use tessera_components::slider::centered_slider;
use tessera_ui::{Dp, Modifier, remember};

let current_value = remember(|| 0.5f32);

current_value.set(0.75);
assert_eq!(current_value.get(), 0.75);

centered_slider()
    .modifier(Modifier::new().width(Dp(200.0)))
    .value(current_value.get())
    .on_change(move |new_value| {
        current_value.set(new_value);
    });

current_value.set(0.25);
assert_eq!(current_value.get(), 0.25);