2 summary:: A wrapper class for a label plus a popUpMenu with per item actions
3 categories:: GUI>EZ-GUI
4 related:: Classes/PopUpMenu
7 EZPopUpMenu is wrapper class which creates an (optional) label and a popUpMenu. It includes per item actions as well as a global action which are both evaluated upon selection of an item. Convenience methods for inserting and deleting menu items are also included . If the parent is nil, then EZPopUpMenu will create its own window.See link::Classes/EZGui:: and link::Classes/EZLists:: for all of the options.
9 subsection:: Some Important Issues Regarding EZPopUpMenu
10 The convenience methods for EZPopUpMenu require that the items array is an array of associations of labels and functions, not like in link::Classes/PopUpMenu::, where items is simply an array of strings. If code::label:: is code::nil::, then no staticText is created.
16 The parent view or window. If the parent is nil, then EZPopUpMenu 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.
19 An instance of link::Classes/Rect:: or link::Classes/Point::. Default value is code::160@22::.
22 The label. Default value is code::nil::. If code::nil::, then no link::Classes/StaticText:: is created.
25 Default value is code::nil::. An link::Classes/Array:: of link::Classes/Association::s code:: ['label' -> { arg menuObj; value }, ] ::. Or and link::Classes/Array:: link::Classes/Symbol::s (if you are only using code::globalAction::).
27 argument:: globalAction
28 A global function to be performed in addition to the item functions code:: { arg menuObj; value } ::.
31 Initial value of the menu, i.e. the index selected. Default value is 0.
34 An instance of link::Classes/Boolean::. Performs the action at code::initVal:: on creation of the menu, plus the code::globalAction::. Default value is code::false::.
39 argument:: labelHeight
40 Default value is 20. Not used if layout is code::\horz::.
43 code::\vert:: or code::\horz::. default is code::\horz::.
46 A link::Classes/Point::. By default, the view tries to get its parent's code::gap::, otherwise it defaults to code::2@2::. Setting it overrides these.
49 A link::Classes/Point::. This will inset the bounds occupied by the subviews of view.
55 w.view.decorator = FlowLayout(w.view.bounds);
61 \item0 ->{|a| ("this is item 0 of " ++ a).postln},
62 \item1 ->{|a| ("this is item 1 of " ++ a).postln},
63 \item2 ->{|a| ("this is item 2 of " ++ a).postln},
65 globalAction: {|a| ("this is a global action of "++a.asString ).postln},
75 // or a more simple syntax:
78 w.view.decorator = FlowLayout(w.view.bounds);
79 g = EZPopUpMenu.new(w, 200@22, "Menu: ");
80 g.addItem(\item0, { |a| ("this is item 0 of " ++ a).postln });
81 g.addItem(\item1, { |a| ("this is item 1 of " ++ a).postln });
82 g.addItem(\item2, { |a| ("this is item 2 of " ++ a).postln });
89 subsection:: Changing Appearance
92 argument:: stringBackground
93 An instance of link::Classes/Color::. The code::background:: of the label and unit views.
94 argument:: stringColor
95 An instance of link::Classes/Color::. The code::stringColor:: of the label and unit views.
96 argument:: menuBackground
97 An instance of link::Classes/Color::. The code::background:: of the menu.
98 argument:: menuStringColor
99 An instance of link::Classes/Color::. The code::stringColor:: of the menu.
100 argument:: background
101 An instance of link::Classes/Color::. The code::background:: of the list view.
104 Set the link::Classes/Font:: used by all the views.
106 An instance of link::Classes/Font::.
110 // try several examples together
114 // inherits the parent's decorator gap
117 w=Window.new("oscillators", Rect(200,500,200,160)).front;
118 w.view.decorator = FlowLayout(w.view.bounds).gap_(2@2);
120 g = EZPopUpMenu.new(w,190@22, "Oscillator % : ".format(i+1));
121 g.addItem(\off, {"off". postln});
122 g.addItem(\sine, {"sine". postln});
123 g.addItem(\saw, {"saw". postln});
124 g.addItem(\pulse, {"pulse". postln});
125 g.setColors(Color.grey,Color.white);
128 w.bounds=w.bounds.moveBy(300,60);
132 // Creates its own window if parentView is nil:
134 g = EZPopUpMenu.new(nil,250@22 ," Select : ");
135 g.addItem(\item0, {"this is item 0". postln});
136 g.addItem(\item1, {"this is item 1". postln});
137 g.addItem(\item2, {"this is item 2". postln});
138 g.setColors(Color.grey,Color.white);
145 g = EZPopUpMenu.new(nil,200@42, " Choose",layout:\vert);
146 g.addItem(\item0, {"this is item 0". postln});
147 g.addItem(\item1, {"this is item 1". postln});
148 g.addItem(\item2, {"this is item 2". postln});
149 g.setColors(Color.grey,Color.white);
150 g.window.bounds=g.window.bounds.moveBy(300,-200);
154 // No labelView created, so set the window title;
156 g = EZPopUpMenu.new(bounds:180@22); // no label
157 g.addItem(\item0, {"this is item 0". postln});
158 g.addItem(\item1, {"this is item 1". postln});
159 g.addItem(\item2, {"this is item 2". postln});
161 g.window.name=" choose item";
162 g.window.bounds=g.window.bounds.moveBy(0,-200);
168 g = EZPopUpMenu.new(nil,200@22, "Menu:");
169 g.addItem(\item0, {"this is item 0". postln});
170 g.addItem(\item1, {"this is item 1". postln});
171 g.addItem(\item2, {"this is item 2". postln});
172 g.addItem(\item4, {"this is item 4". postln});
176 g.insertItem(3, \item3, {"this is item 3". postln});
183 w.view.decorator = FlowLayout(w.view.bounds);
184 g = EZPopUpMenu.new(w,200@22, "Menu:");
185 g.addItem(\item0, {"this is item 0". postln});
186 g.addItem(\item1, {"this is item 1". postln});
187 g.addItem(\item2, {"this is item 2". postln});
188 g.addItem(\item4, {"this is item 4". postln});
189 g.insertItem(3, \item3, {"this is item 3". postln});
199 g = EZPopUpMenu.new(nil,200@22, "List:");
200 g.addItem(\item0, {"this is item 0". postln});
201 g.addItem(\item1, {"this is item 1". postln});
202 g.addItem(\item2, {"this is item 2". postln});
203 g.addItem(\item3, {"this is item 3". postln});
206 g.replaceItemAt(2, \item2_replaced, {"this is item 2 replaced". postln});