2 var <maxItems=1, <numItems=1, <>action, <spec;
5 *new { |w, bounds, maxItems, numItems, action, initVal=0|
6 ^super.newCopyArgs(maxItems, numItems, action)
7 .init(w, bounds, initVal);
9 init { |w, bounds, initVal|
10 slider = GUI.slider.new(w, bounds);
11 slider.action = { |sl|
12 this.valueAction_(spec.map(sl.value));
14 slider.keyDownAction { arg char, modifiers, unicode,keycode;
15 if (unicode == 16rF700, { this.increment; ^this });
16 if (unicode == 16rF703, { this.increment; ^this });
17 if (unicode == 16rF701, { this.decrement; ^this });
18 if (unicode == 16rF702, { this.decrement; ^this });
20 spec = [0, 0, \lin, 1].asSpec;
24 increment { this.valueAction = this.value + this.spec.step }
25 decrement { this.valueAction = this.value + this.spec.step }
28 var slBounds = slider.bounds;
29 var maxLength = slBounds.width max: slBounds.height + 2;
30 var numTooMany = (numItems - maxItems).max(1);
31 var fractionToShow = (maxItems / numItems).min(1);
32 if (GUI.scheme.id == \cocoa) {
33 // swingOSC posts a 'not implemented yet' warning.
34 slider.thumbSize = fractionToShow * maxLength;
36 // slider.step_(1 / numTooMany.max(1)); // this does the action - it should not.
37 slider.setProperty(\step, 1 / numTooMany.max(1));
38 spec.minval_(numTooMany); // minval to invert spec
42 value = spec.constrain(val);
43 slider.value_(spec.unmap(value));
46 maxItems_ { |val| maxItems = val.max(1); this.adjust }
47 numItems_ { |val| numItems = val.max(1); this.adjust }
49 valueAction_ { |val| this.value_(val).doAction; }
50 doAction { action.value(this) }
52 enabled { ^slider.enabled }
53 enabled_ { |flag| slider.enabled_(flag) }
54 visible { ^slider.visible }
55 visible_ { |flag| slider.visible_(flag) }
57 remove { slider.remove }