pub fn centered_slider(args: impl Into<SliderArgs>, state: SliderState)Expand description
§centered_slider
Renders an interactive slider that originates from the center (0.5), allowing selection of a value between 0.0 and 1.0. The active track extends from the center to the handle, while inactive tracks fill the remaining space.
§Usage
Use for adjustments that have a neutral midpoint, such as balance controls or deviation settings.
§Parameters
args— configures the slider’s value, appearance, and callbacks; seeSliderArgs.state— a clonableSliderStateto manage interaction state like dragging and focus.
§Examples
use std::sync::{Arc, Mutex};
use tessera_ui::{DimensionValue, Dp};
use tessera_ui_basic_components::slider::{centered_slider, SliderArgsBuilder, SliderState};
let slider_state = SliderState::new();
let current_value = Arc::new(Mutex::new(0.5));
// Simulate a value change
{
let mut value_guard = current_value.lock().unwrap();
*value_guard = 0.75;
assert_eq!(*value_guard, 0.75);
}
centered_slider(
SliderArgsBuilder::default()
.width(DimensionValue::Fixed(Dp(200.0).to_px()))
.value(*current_value.lock().unwrap())
.on_change(Arc::new(move |new_value| {
// In a real app, you would update your state here.
// For this example, we'll just check it after the simulated change.
println!("Centered slider value changed to: {}", new_value);
}))
.build()
.unwrap(),
slider_state.clone(),
);
// Simulate another value change and check the state
{
let mut value_guard = current_value.lock().unwrap();
*value_guard = 0.25;
assert_eq!(*value_guard, 0.25);
}