deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / GUI / Base / EZScroller.sc
blobab03f54dc33a577632ce4db0a3718eddbaf7bfb0
1 EZScroller {
2         var <maxItems=1, <numItems=1, <>action, <spec;
3         var <value, <slider;
5         *new { |w, bounds, maxItems, numItems, action, initVal=0|
6                 ^super.newCopyArgs(maxItems, numItems, action)
7                         .init(w, bounds, initVal);
8         }
9         init { |w, bounds, initVal|
10                 slider = GUI.slider.new(w, bounds);
11                 slider.action = { |sl|
12                         this.valueAction_(spec.map(sl.value));
13                 };
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 });
19                 };
20                 spec = [0, 0, \lin, 1].asSpec;
21                 this.adjust;
22                 this.value_(initVal);
23         }
24         increment { this.valueAction = this.value + this.spec.step }
25         decrement { this.valueAction = this.value + this.spec.step }
27         adjust {
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;
35                 };
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
39         }
41         value_ { |val|
42                 value = spec.constrain(val);
43                 slider.value_(spec.unmap(value));
44         }
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 }