InputRange
InputRange[min_, max_, step_:1, initial_:(min+max)/2, opts___] _EventObjectcreates a basic combo of a slider and numerical input field and returns EventObject
Event generation
Every-time user drags a slider, an event in a form of number will be generated
slider = InputRange[0,1,0.1];
EventHandler[slider, Function[data,
Print[StringTemplate["`` is a number"][data]]
]];
sliderOn MacOS devices it provides a haptic feedback when dragged
Options
"Label"
Adds a label to a slider
slider = InputRange[0, 1, 0.1, "Label"->"Slider"]"Topic"
Specifies which topic or pattern of an event is used
"Topic" -> name_Stringemits name for each time when user drags a slider
"Topic" -> {oninput_String, onchange_String}emits oninput when any changes occur, while onchange is emitted after the users action. Null value will suppress event generation, i.e. to make onchange only slider
"Topic" -> {Null, "Default"}"TrackedExpression"
Adds expression to track (usually a symbol) and update the slider position
var = 0.3;
EventHandler[InputRange[0,2,0.1, var, "TrackedExpression"->Offload[var], Print]Now you can overwrite slider position by setting
var = 0.6;Your slider effectively acquires an initialization value because of tracked expression
Debouncing
To prevent an event propagation, when a tracked symbol is updated use
"TrackedExpression"->{Offload[var], "Debounce"}then you can safely write
var = 0.3;
EventHandler[InputRange[0,2,0.1, var, "TrackedExpression"->{Offload[var], "Debounce"}], Function[newValue,
var = newValue
]]
Then InputRange will remember its state
Appearance
By the default is Automatic.
Possible value: "FineTuning" - adds a fine control element to vary the range value .
Chaining events
One can reuse another event for a new element
InputRange[event_EventObject, min_, max_, step_:1, initial_:(min+max)/2, opts___]for example
ev = EventObject[];
InputButton[ev, "Topic"->"Button"]
InputRange[ev, 0,1,0.1, "Topic"->"Slider"]
EventHandler[ev, {
"Button" -> Beep,
"Slider" -> Print
}];Applications
Control properties using knob
EventHandler[InputRange[0,1,0.1], Function[data, pos = data]];
%
% // EventFire;
Graphics[Rectangle[{-1,0}, {1, Offload[pos]}]]