2 var <numberView, <unitView, <>controlSpec,
3 numSize,numberWidth,unitWidth, gap, gap2;
6 var scaler=1; //for swing compatibility
7 *new { arg parent, bounds, label, controlSpec, action, initVal,
8 initAction=false, labelWidth=60, numberWidth,
9 unitWidth=0, labelHeight=20, layout=\horz, gap, margin;
11 ^super.new.init(parent, bounds, label, controlSpec, action,
12 initVal, initAction, labelWidth, numberWidth,
13 unitWidth, labelHeight, layout, gap, margin)
16 init { arg parentView, bounds, label, argControlSpec, argAction, initVal,
17 initAction, labelWidth, argNumberWidth,argUnitWidth,
18 labelHeight, argLayout, argGap, argMargin;
20 var labelBounds, numBounds, unitBounds;
24 this.prMakeMarginGap(parentView, argMargin, argGap);
27 unitWidth = argUnitWidth;
28 numberWidth = argNumberWidth;
31 bounds.isNil.if {bounds= 160@20};
33 // if no parent, then pop up window
34 # view,bounds = this.prMakeView( parentView,bounds);
36 numberWidth.isNil.if{numberWidth=45}{
37 labelWidth=bounds.width-unitWidth-numberWidth; //override the labelWidth
38 if (layout==\line2){unitWidth=bounds.width-numberWidth}; //override the unitWidth
40 labelSize=labelWidth@labelHeight;
41 numSize = numberWidth@labelHeight;
44 # labelBounds,numBounds, unitBounds
45 = this.prSubViewBounds(innerBounds, label.notNil, unitWidth>0);
49 label.notNil.if{ //only add a label if desired
50 labelView = GUI.staticText.new(view, labelBounds);
52 {labelView.align = \left;}
53 {labelView.align = \right;};
54 labelView.string = label;
57 (unitWidth>0).if{ //only add a unitLabel if desired
58 unitView = GUI.staticText.new(view, unitBounds);
61 // set view parameters and actions
62 controlSpec = argControlSpec.asSpec; // let default to nil.asSpec!
63 (unitWidth>0).if{ unitView.string = " "++controlSpec.units.asString};
64 initVal = initVal ? controlSpec.default;
67 numberView = GUI.numberBox.new(view, numBounds).resize_(2);
69 numberStep = controlSpec.step;
70 if (numberStep == 0) {
71 numberStep = controlSpec.guessNumberStep;
73 // controlSpec wants a step, so zooming in with alt is disabled.
74 numberView.alt_scale = 1.0
77 numberView.step = numberStep;
78 numberView.scroll_step = numberStep;
79 numberView.scroll=true;
82 this.valueAction_(numberView.value);
86 this.valueAction = initVal;
95 value = controlSpec.constrain(val);
96 numberView.value = value.round(round);
98 valueAction_ { arg val;
102 doAction { action.value(this) }
104 set { arg label, spec, argAction, initVal, initAction=false;
105 labelView.notNil.if { labelView.string = label.asString };
106 spec.notNil.if { controlSpec = spec.asSpec };
107 argAction.notNil.if { action = argAction };
108 initVal = initVal ? value ? controlSpec.default;
110 this.valueAction_(initVal);
112 this.value_(initVal);
116 setColors{ arg stringBackground, stringColor,numBackground,numStringColor,
117 numNormalColor, numTypingColor, background ;
119 stringBackground.notNil.if{
120 labelView.notNil.if{labelView.background_(stringBackground)};
121 unitView.notNil.if{unitView.background_(stringBackground)};};
122 stringColor.notNil.if{
123 labelView.notNil.if{labelView.stringColor_(stringColor)};
124 unitView.notNil.if{unitView.stringColor_(stringColor)};};
125 numBackground.notNil.if{
126 numberView.background_(numBackground); };
127 numNormalColor.notNil.if{
128 numberView.normalColor_(numNormalColor);};
130 numTypingColor.notNil.if{
131 numberView.typingColor_(numTypingColor);};
132 numStringColor.notNil.if{
133 numberView.stringColor_(numStringColor);};
134 background.notNil.if{
135 view.background=background;};
141 labelView.notNil.if{labelView.font=font};
142 unitView.notNil.if{unitView.font=font};
143 numberView.font=font;
146 /////// Private methods /////////
148 prSetViewParams{ // sets resize and alignment for different layouts
152 labelView.notNil.if{labelView.resize_(2)};
153 unitView.notNil.if{unitView.resize_(6)};
154 numberView.resize_(5);
158 labelView.resize_(4).align_(\right);
159 numberView.resize_(5);
160 unitView.notNil.if{unitView.resize_(6)};
162 unitView.notNil.if{ unitView.resize_(6)};
163 numberView.resize_(5);
166 popUp.if{view.resize_(2)};
169 prSubViewBounds{arg rect, hasLabel, hasUnit;
170 var numBounds,labelBounds,sliderBounds;
171 var unitBounds, gap1, gap2, numY;
174 hasLabel.not.if{ gap1 = 0@0; labelSize=0@0};
175 hasUnit.not.if{gap2 = 0@0};
180 labelBounds = Rect( // fill the line
187 numSize.y=numSize.y-gap1.y;
188 numY=labelBounds.height+gap1.y;
189 unitBounds = Rect( rect.width - unitWidth, // //adjust to fit
190 numY, unitWidth, rect.height-labelSize.y-gap1.y);
191 numBounds = Rect(0, numY,
192 rect.width-unitWidth-gap2.x, rect.height-labelSize.y-gap1.y); // to right
197 labelSize.y=rect.height;
198 labelBounds = (labelSize.x@labelSize.y).asRect; // to left
199 unitBounds = (unitWidth@labelSize.y).asRect.left_(rect.width-unitWidth); // to right
200 numBounds = Rect( //adjust to fit
201 labelBounds.width+gap1.x,
203 rect.width - labelBounds.width - unitBounds.width - gap1.x - gap2.x ,
209 ^[labelBounds, numBounds, unitBounds].collect{arg v; v.moveBy(margin.x,margin.y)}