pub fn glass_slider(
args: impl Into<GlassSliderArgs>,
state: Arc<Mutex<GlassSliderState>>,
)
Expand description
Creates a slider component with a frosted glass effect.
The glass_slider
allows users to select a value from a continuous range (0.0 to 1.0)
by dragging a handle along a track. It features a modern, semi-transparent
“glassmorphism” aesthetic, with a blurred background and subtle highlights.
§Arguments
args
- An instance ofGlassSliderArgs
orGlassSliderArgsBuilder
to configure the slider’s appearance and behavior.value
: The current value of the slider, must be between 0.0 and 1.0.on_change
: A callback function that is triggered when the slider’s value changes. It receives the new value as anf32
.
state
- AnArc<Mutex<GlassSliderState>>
to manage the component’s interactive state, such as dragging and focus.
§Example
use std::sync::Arc;
use parking_lot::Mutex;
use tessera_ui_basic_components::glass_slider::{glass_slider, GlassSliderArgsBuilder, GlassSliderState};
// In your application state
let slider_value = Arc::new(Mutex::new(0.5));
let slider_state = Arc::new(Mutex::new(GlassSliderState::new()));
// In your component function
let value = *slider_value.lock();
let on_change_callback = {
let slider_value = slider_value.clone();
Arc::new(move |new_value| {
*slider_value.lock() = new_value;
})
};
glass_slider(
GlassSliderArgsBuilder::default()
.value(value)
.on_change(on_change_callback)
.build()
.unwrap(),
slider_state.clone(),
);