use fission::prelude::*;
#[derive(Debug)]
pub struct PlayerState { volume: f32 }
impl Default for PlayerState {
fn default() -> Self { Self { volume: 0.5 } }
}
impl GlobalState for PlayerState {}
#[fission_reducer(SetVolume, no_eq)]
fn set_volume(state: &mut PlayerState, value: f32) {
if value.is_finite() {
state.volume = value.clamp(0.0, 1.0);
}
}
fission_component! {
pub VolumeControl<PlayerState> {}
view(_control, state, cx) {
let change = cx.bind(SetVolume(state.volume), reduce!(set_volume));
} =>
Slider(
id: WidgetId::explicit("player.volume"),
semantics_identifier: Some("player.volume".into()),
label: Some(cx.tr("player.volume")),
value: state.volume,
min: 0.0,
max: 1.0,
step: 0.05,
on_change: change,
)
}
Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id | Option<WidgetId> | Stable widget identity. | Defaults to None. |
value | f32 | Current slider value. | Defaults to 0.0. Values are rendered relative to min and max. |
min | f32 | Minimum value in the domain. | Defaults to 0.0. |
max | f32 | Maximum value in the domain. | Defaults to 1.0. |
label | Option<String> | Accessible name. | Supply the operation rather than a generic slider label. |
semantics_identifier | Option<String> | Stable semantic/test identifier. | Independent of translated copy. |
step | Option<f32> | Positive snapping/key increment. | Omit for continuous pointer movement. |
labelled_by | Vec<WidgetId> | Visible label relationships. | Refer to the actual named label nodes. |
on_change | Option<ActionEnvelope> | Action dispatched while the user drags. | The runtime serializes the new f32 value into the action payload. |