3 summary:: A view consisting of a sliding handle.
8 A view that allows setting a numerical value by means of moving a sliding handle. It can have horizontal or vertical orientation, meaning the direction in which the handle moves.
19 When a new Slider is created, its link::#-orientation:: is determined by the initial size: if it is wider than high, the orientation will be horizontal, otherwise it will be vertical.
32 Numerical value between 0 and 1, represented by the handle position within the groove.
38 Sets link::#-value:: and triggeres link::#-action::.
41 Increments the value by link::#-step:: multiplied by 'factor'.
47 Decrements the value by link::#-step:: multiplied by 'factor'.
55 SUBSECTION:: Appearance
58 The orientation of the Slider - the direction in which the handle moves. The default value depends on the size of the view when created.
61 One of the two Symbols: \horizontal or \vertical.
64 The size of the handle - its width or height, depending on link::#-orientation::.
67 An Integer amount of pixels.
70 The color of the handle.
77 SUBSECTION:: Interaction
80 The amount by which the value will changed when link::#-increment:: or link::#-decrement:: is called, or when related keys are pressed.
86 The absolute amount by which the value would change if the handle moved by one pixel.
92 The factor by which link::#-step:: is multiplied when incrementing or decrementing the value by keyboard while the Shift key is pressed.
98 The factor by which link::#-step:: is multiplied when incrementing or decrementing the value by keyboard while the Ctrl key is pressed.
104 The factor by which link::#-step:: is multiplied when incrementing or decrementing the value by keyboard while the Alt key is pressed.
113 The action object evaluated whenever the user moves the handle.
115 METHOD:: defaultKeyDownAction
117 Implements the default effects of key presses as follows:
120 ## strong::Key:: || strong::Effect::
121 ## r || valueAction_(1.0.rand)
122 ## n || valueAction_(0)
123 ## x || valueAction_(1)
124 ## c || valueAction_(0.5)
127 ## up arrow || increment
128 ## down arrow || decrement
129 ## right arrow || increment
130 ## left arrow || decrement
135 SUBSECTION:: Drag and drop
137 METHOD:: defaultGetDrag
141 METHOD:: defaultCanReceiveDrag
143 True if the current drag data is a number.
145 METHOD:: defaultReceiveDrag
146 Sets link::#-valueAction:: to the current drag data.
151 subsection:: Show the slider value in a NumberBox
154 w = Window.new.front;
155 c = NumberBox(w, Rect(20, 20, 150, 20));
156 a = Slider(w, Rect(20, 60, 150, 20))
163 ( // change the bounds to become vertical
164 w = Window.new.front;
165 c = NumberBox(w, Rect(20, 20, 150, 20));
166 a = Slider(w, Rect(200, 60, 20, 150))
174 subsection:: Use a Spec to round and map the output range
177 w = Window.new.front;
178 b = ControlSpec(-50, 50, \linear, 0.01); // min, max, mapping, step
179 c = StaticText(w, Rect(20, 20, 150, 20)).align_(\center).background_(Color.rand);
180 a = Slider(w, Rect(20, 50, 150, 20))
181 .focusColor_(Color.red(alpha:0.2))
182 .background_(Color.rand)
185 c.string_(b.map(a.value).asString)
186 // round the float so it will fit in the NumberBox
193 subsection:: Change the stepsize of the slider, selected via a PopUpMenu
196 w = Window.new.front;
197 a = ["0", "0.0625", "0.125", "0.25", "0.5", "1"];
198 b = Slider(w, Rect(20, 100, 100, 20))
201 }).background_(Color.rand);
202 d = PopUpMenu(w, Rect(20, 60, 100, 20))
205 b.step_((a.at(d.value)).asFloat);
207 StaticText(w, Rect(130, 60, 100, 20)).string_("change step");
208 c = NumberBox(w, Rect(20, 20, 100, 20));
212 subsection:: Use the slider view to accept key actions
214 ( // select the slider, type something and watch the post window
216 c = Slider(w,Rect(0,0,100,30));
217 c.keyDownAction = { arg view,char,modifiers,unicode,keycode;
218 [char,modifiers,unicode,keycode].postln;
224 subsection:: Adding functionality to a view by the method addAction
225 This is useful for adding things to existing frameworks that have action functions already.
228 w = Window.new("A Slider");
229 a = Slider.new(w, Rect(40, 10, 300, 30));
233 // now incrementally add some action to the slider
234 a.addAction({ |sl| sl.value.postln });
235 a.addAction({ |sl| w.view.background = Color.green(sl.value) });
236 a.addAction({ |sl| sl.background = Color.red(1 - sl.value) });
238 // adding and removing an action:
239 f = { |sl| "--------*******-------".postln; };
243 // or remove all, of course
247 subsection:: Use Slider for triggering sounds
251 SynthDef(\pluck,{arg freq=55;
253 Pluck.ar(WhiteNoise.ar(0.06),
254 EnvGen.kr(Env.perc(0,4), 1.0, doneAction: 2),
263 w = Window.new("Hold arrow keys to trigger sound",Rect(300,Window.screenBounds.height-300,400,100)).front;
264 a = Slider(w, Rect(50, 20, 300, 40))
269 // trigger a synth with varying frequencies
270 Synth(\pluck, [\freq,55+(1100*a.value)]);
271 w.view.background_(Gradient(Color.rand,Color.rand));
278 subsection:: Change background color of Window
281 w = Window("RGB fader", Rect(100, 500, 400, 400))
283 f = { w.view.background_(Color.new(r.value, g.value, b.value, 1)) };
284 r = Slider(w, Rect(100, 140, 200, 20))
286 .action_({ f.value });
287 g = Slider(w, Rect(100, 170, 200, 20))
289 .action_({ f.value });
290 b = Slider(w, Rect(100, 200, 200, 20))
292 .action_({ f.value });