3 w = SCWindow.new.front;
4 a = SCTextField2(w, Rect(10, 10, 100, 20));
5 b = SCTextField2(w, Rect(10, 100, 250, 40));
6 c = SCTextField(w, Rect(10, 200, 250, 20)).string_("old-style text box");
8 a.action = {arg field; field.value.postln; };
13 a.valueAction = "yoooo";
15 a.boxColor_(Color.yellow)
28 // Drag-and-drop NOWORKY:
30 a.defaultCanReceiveDrag
34 a.font_(Font(Font.defaultSerifFace))
35 a.font_(Font(Font.defaultSansFace), 8)
39 a.stringColor_(Color.red)
42 SCTextField : SCStaticTextBase {
44 *paletteExample { arg parent, bounds;
45 // ^this.new(parent, bounds).initBackGround.value_("edit me");
46 ^this.new(parent, bounds).value_("edit me");
52 background = Color.white;
60 ^this.getProperty(\string);
67 ^this.string_(str).doAction;
70 this.deprecated(thisMethod, SCView.findMethod(\background));
73 boxColor_ { arg color;
74 this.deprecated(thisMethod, SCView.findMethod(\background_));
75 this.background_(color)
78 ^super.properties ++ #[\boxColor]
81 // Dragging doesn't seem to be working here
83 //"defaultGetDrag was called".postln;
86 defaultCanReceiveDrag {
87 //"defaultCanReceiveDrag was called".postln;
88 ^currentDrag.respondsTo(\asString)
91 //"defaultReceiveDrag was called".postln;
92 this.valueAction = currentDrag;
96 // prClose removes action here, to prevent action acting on textview after it's gone
97 prClose { dataptr = nil; action = nil; onClose.value(this); }
101 SCNumberBox : SCTextField {
104 var <>step=1, <>scroll_step=1;
105 var <>typingColor, <>normalColor;
106 var <>clipLo = -inf, <>clipHi = inf, hit, inc=1.0, <>scroll=true;
107 var <>shift_scale = 100.0, <>ctrl_scale = 10.0, <>alt_scale = 0.1;
108 //var mouseIncOrDeced = true;
110 getScale { |modifiers|
112 { modifiers & 131072 == 131072 } { shift_scale }
113 { modifiers & 262144 == 262144 } { ctrl_scale }
114 { modifiers & 524288 == 524288 } { alt_scale }
118 *paletteExample { arg parent, bounds;
120 v = this.new(parent, bounds);
125 // init { arg argParent, argBounds;
126 // typingColor = Color.red;
127 // normalColor = Color.black;
128 // background = Color.white;
129 // parent = argParent.asView; // actual view
130 // this.prInit(parent.asView, argBounds.asRect,this.class.viewClass);
131 // argParent.add(this);//maybe window or viewadapter
134 // clipLo_ {|val = -inf|
136 // this.setProperty(\clipLo, val);
139 // clipHi_ {|val = inf|
141 // this.setProperty(\clipHi, val);
144 increment {arg mul=1; this.valueAction = this.value + (step*mul); }
145 decrement {arg mul=1; this.valueAction = this.value - (step*mul); }
147 defaultKeyDownAction { arg char, modifiers, unicode;
148 var zoom = this.getScale(modifiers);
151 if (unicode == 16rF700, { this.increment(zoom); ^this });
152 if (unicode == 16rF703, { this.increment(zoom); ^this });
153 if (unicode == 16rF701, { this.decrement(zoom); ^this });
154 if (unicode == 16rF702, { this.decrement(zoom); ^this });
156 // if ((char == 3.asAscii) || (char == $\r) || (char == $\n), { // enter key
157 // if (keyString.notNil,{ // no error on repeated enter
158 // this.valueAction_(keyString.asFloat);
162 // if (char == 127.asAscii, { // delete key
164 // this.string = object.asString;
165 // this.stringColor = normalColor;
168 // if (char.isDecDigit || "+-.eE".includes(char), {
169 // if (keyString.isNil, {
170 // keyString = String.new;
171 // this.stringColor = typingColor;
173 // keyString = keyString.add(char);
174 // this.string = keyString;
180 ^nil // bubble if it's an invalid key
186 // this.stringColor = normalColor;
187 // object = val !? { val.clip(clipLo, clipHi) };
188 // this.string = object.asString;
190 // valueAction_ { arg val;
193 // this.value = val !? { val.clip(clipLo, clipHi) };
194 // if (object != prev, { this.doAction });
198 // this.deprecated(thisMethod, SCView.findMethod(\background));
201 // boxColor_ { arg color;
202 // this.deprecated(thisMethod, SCView.findMethod(\background_));
203 // this.background_(color)
207 ^super.properties ++ #[\boxColor]
212 defaultCanReceiveDrag {
213 ^currentDrag.isNumber;
216 this.valueAction = currentDrag;
219 mouseDown { arg x, y, modifiers, buttonNumber, clickCount;
221 if (scroll == true, { inc = this.getScale(modifiers) });
222 mouseDownAction.value(this, x, y, modifiers, buttonNumber, clickCount)
225 mouseMove { arg x, y, modifiers;
227 if (scroll == true, {
228 //mouseIncOrDeced = true;
230 // horizontal or vertical scrolling:
231 if ( (x - hit.x) < 0 or: { (y - hit.y) > 0 }) { direction = -1.0; };
233 this.valueAction = (this.value + (inc * this.scroll_step * direction));
236 mouseMoveAction.value(this, x, y, modifiers);
240 //if(mouseIncOrDeced, {this.value = this.value;mouseIncOrDeced = false});
246 ^this.getProperty(\value);
250 val = val !? { val.clip(clipLo, clipHi) };
251 this.setProperty(\value, val);
254 valueAction_ { arg val;
257 val = val !? { val.clip(clipLo, clipHi) };
258 if (val != prev, { this.value_(val); this.doAction });
261 // validate range here
264 current = this.value;
265 if(current.inclusivelyBetween(clipLo, clipHi).not, {
266 this.value = current; // clips here