2 summary:: Wrapper class for a label, a text field and a value
3 categories:: GUI>EZ-GUI
4 related:: Classes/StaticText, Classes/TextField
7 EZText is a wrapper class which creates an (optional) link::Classes/StaticText::, and a link::Classes/TextField::. The value is displayed as a compileString in the text field for editing.
9 subsection:: Some Important Issues Regarding EZText
10 If the parent is code::nil::, then EZText will create its own link::Classes/Window::. See link::Classes/EZGui:: for more options.
14 subsection:: Creation / Class Methods
19 The parent view or window. If the parent is nil, then EZText will create its own link::Classes/Window::, and place it conveniently on the screen if the bounds are a link::Classes/Point::. If the bounds are a link::Classes/Rect::, then the link::Classes/Rect:: determines the window bounds.
22 An instance of link::Classes/Rect:: or link::Classes/Point::. Default value is code::160@20::.
25 The label. Default value is code::nil::. If code::nil::, then no link::Classes/StaticText:: is created.
28 A link::Classes/Function:: called when the value changes. The function is passed the EZText instance as its argument.
31 The value to initialize the EZText with.
34 A link::Classes/Boolean:: indicating whether the action function should be called when setting the initial value. The default is false.
37 Number of pixels width for the label. The default is 60. In the code::\horz:: layout, if you specify the code::textWidth::, then the code::labelWidth:: is ignored and is set to the code::bounds.width - textWidth::.
40 Number of pixels width for the number box. The default is 45. In code::\vert:: layout, code::textWidth:: defaults to the code::bounds.width::.
42 argument:: labelHeight
46 code::\vert::, or code::\horz::. The default is code::\horz::; code::\vert:: is a two line version.
49 A link::Classes/Point::. By default, the view tries to get its parent's gap, otherwise it defaults to code::2@2::. Setting it overrides these.
52 A link::Classes/Point::. This will inset the bounds occupied by the subviews of view.
58 w = Window("EZText", Rect(300, 300, 260, 60)).front;
59 g = EZText( w, // parent
62 { |ez| (ez.value.asString ++" is the value of " ++ ez).postln }, // action
63 [1, 2, 3], // initValue
66 g.setColors(Color.grey,Color.white);
69 // Simplest version, no parent view, so a window is created
71 g = EZText(label:" test ");
72 g.action_({ |ez| (ez.value.asString ++" is the value of " ++ ez).postln });
76 g = EZText(bounds: Rect( 100, 200, 150, 50), label:" test ", layout: \vert);
77 g.action_({ |ez| (ez.value.asString ++" is the value of " ++ ez).postln });
80 The contained views can be accessed via the EZText instance variables: code::labelView::, code::textField::.
85 Returns the textField.
88 A link::Classes/Function:: to be evaluated when the value changes. Typical use is to type in a new value, and interpret it by hitting the evaluation shortcut. The first argument to the function will be the EZText.
91 Gets/sets the value of the ezText. Does not perform the action.
96 Sets the value and performs the action.
104 Sets/gets whether the textfield is enabled.
106 An instance of link::Classes/Boolean::. Default is code::true::.
109 subsection:: Changing Appearance
112 argument:: stringBackground
113 An instance of link::Classes/Color::. The code::background:: of the label and unit views.
114 argument:: stringColor
115 An instance of link::Classes/Color::. The code::stringColor:: of the label and unit views.
116 argument:: textBackground
117 An instance of link::Classes/Color::. The code::background:: of the textField.
118 argument:: numStringColor
119 An instance of link::Classes/Color::. The code::stringColor:: of the textField.
120 argument:: numNormalColor
121 An instance of link::Classes/Color::. The code::normalColor:: of the textField.
122 argument:: numTypingColor
123 An instance of link::Classes/Color::. The code::typingColor:: of the textField.
124 argument:: background
125 An instance of link::Classes/Color::. The code::background:: of the enclosing view.
128 Set the Font used by all the views.
130 An instance of link::Classes/Font::.
136 w=Window("ez", Rect(300, 300, 300, 50)).front;
137 g=EZText(w, 290@40," test ", textWidth: 220,layout:\horz);
138 g.setColors(Color.grey,Color.white);
142 // lots of textFields on one window
145 w.view.decorator=FlowLayout(w.view.bounds);
146 w.view.decorator.gap=2@2;
149 g=EZText(w, 170@16," test ", textWidth: 120,layout:\horz);
150 g.setColors(Color.grey, Color.white, Color.grey(0.8));
155 // click these parentheses to see three variants
159 m=2@2; //comment for no margin
165 g=EZText(nil, 170@20," freq ", textWidth:120,layout:\horz,margin:m);
166 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
167 g.window.bounds = g.window.bounds.moveBy(-180,50);
170 ( // no label. use window name as label
171 g=EZText(nil, 120@20, layout:\horz,margin:m);
172 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
173 g.window.bounds = g.window.bounds.moveBy(-180, -90);
174 g.window.name="Freq";
181 g=EZText(nil, 120@60," freq ", textWidth: 120,layout: \vert, margin:m);
182 g.setColors(Color.grey,Color.white,background: Color.grey(0.7));
183 g.window.bounds = g.window.bounds.moveBy(100,50);
190 // Simplest sound example
192 Tdef(\text).set(\note, [0, 2, 7], \dur, { [0.1, 0.2].choose });
194 w = Window("EZTexts", Rect(200, 400, 304, 120)).front;
197 TdefGui(Tdef(\text), 0, w);
198 Tdef(\text).envir.keysValuesDo { |k, v|
199 EZText(w, Rect(0,0,300,40), k, { |ez|
200 Tdef(\text).envir.put(*[k, ez.value].postcs);
208 (note: ev.note, dur: mydur).postln.play;
214 // type these or similar functions into dur and note fields and evaluate:
216 { [0.1, 0.2, 0.3].choose }
217 { [ 0, 2, 7, 10 ].scramble.keep(rrand(0, 4)) }