pub const SLIDER: &str = "type Slider {\n label: Str = \"Slider\";\n action: func(Number) -> Res[Unit, DataError] = ignore_number;\n min: Number = 0;\n max: Number = 1;\n value: Number = 0;\n}";Expand description
A host-rendered numeric control with a typed value action.
The host supplies a Number to action. A callback accepting input owns any
update to Slider.value; schema construction and host input do not mutate it automatically.
§Declaration
type Slider {
label: Str = "Slider";
action: func(Number) -> Res[Unit, DataError] = ignore_number;
min: Number = 0;
max: Number = 1;
value: Number = 0;
}§Fields and methods
-
label: Visible label; defaults to Slider. -
action: Typed callback accepting the requested numeric value; defaults to ignore_number. -
min: Lower requested bound; defaults to 0. Hosts should present min no greater than max. -
max: Upper requested bound; defaults to 1. Hosts should present max no less than min. -
value: Current requested numeric value; defaults to 0 and changes only through explicit checked state updates.
§Inspect defaults
The default range is 0 through 1.
let slider = Slider {};
print(slider.max);§Expose a changeable control
Change Gain: set_gain clamps the input, updates the stored Slider value, and logs the accepted value.
func set_gain(value: Number) -> Res[Unit, DataError] {
let mut slider = get[Slider](control);
let accepted = value.clamp(slider.min, slider.max)?;
slider.value = accepted;
set(control, slider);
print(accepted);
ret Ok(());
}
let control = spawn(Slider { label: "Gain", action: set_gain, min: 0, max: 2, value: 1 });
print("slider ready");