Function cosmic::iced_widget::slider
source · pub fn slider<'a, T, Message, Theme>(
range: RangeInclusive<T>,
value: T,
on_change: impl Fn(T) -> Message + 'a,
) -> Slider<'a, T, Message, Theme>
Expand description
Creates a new Slider
.
Sliders let users set a value by moving an indicator.
§Example
use iced::widget::slider;
struct State {
value: f32,
}
#[derive(Debug, Clone)]
enum Message {
ValueChanged(f32),
}
fn view(state: &State) -> Element<'_, Message> {
slider(0.0..=100.0, state.value, Message::ValueChanged).into()
}
fn update(state: &mut State, message: Message) {
match message {
Message::ValueChanged(value) => {
state.value = value;
}
}
}