rsc3/doc-schelp/Help-3.12.2/Classes/EZPopUpMenu.html

215 lines
14 KiB
HTML
Raw Normal View History

2022-08-24 13:53:18 +00:00
<html><head><title>EZPopUpMenu</title>
<link rel='stylesheet' href='./../scdoc.css' type='text/css' />
<link rel='stylesheet' href='./../frontend.css' type='text/css' />
<link rel='stylesheet' href='./../custom.css' type='text/css' />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script src='./../scdoc.js' type='text/javascript'></script>
<script src='./../docmap.js' type='text/javascript'></script>
<script src='./../prettify.js' type='text/javascript'></script>
<script src='./../lang-sc.js' type='text/javascript'></script>
<script type='text/javascript'>var helpRoot='./..';</script>
</head>
<ul id='menubar'></ul>
<body onload='fixTOC();prettyPrint()'>
<div class='contents'>
<div class='header'>
<div id='label'>SuperCollider CLASSES</div>
<div id='categories'><a href='./../Browse.html#GUI>EZ-GUI'>GUI>EZ-GUI</a></div>
<h1>EZPopUpMenu</h1>
<div id='summary'>A wrapper class for a label plus a popUpMenu with per item actions</div>
</div>
<div class='subheader'>
<div id='filename'>Source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/GUI/Base/EZPopUpMenu.sc'>/Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/GUI/Base/EZPopUpMenu.sc</a></div><div id='superclasses'>Inherits from: <a href="../Classes/EZLists.html">EZLists</a> : <a href="../Classes/EZGui.html">EZGui</a> : <a href="../Classes/Object.html">Object</a></div>
<div id='related'>See also: <a href="./../Classes/PopUpMenu.html">PopUpMenu</a></div>
</div>
<div id='toc'>
<ul class='toc'><li class='toc1'><a href='#description'>Description</a></li>
<ul class='toc'><li class='toc2'><a href='#Some%20Important%20Issues%20Regarding%20EZPopUpMenu'>Some Important Issues Regarding EZPopUpMenu</a></li>
<ul class='toc'></ul></ul><li class='toc1'><a href='#classmethods'>Class methods</a></li>
<ul class='toc'><li class='toc3'><a href='#*new'>new</a> </li>
<li class='toc2'><a href='#Inherited%20class%20methods'>Inherited class methods</a></li>
</ul><li class='toc1'><a href='#instancemethods'>Instance methods</a></li>
<ul class='toc'><li class='toc2'><a href='#Changing%20Appearance'>Changing Appearance</a></li>
<ul class='toc'><li class='toc3'><a href='#-setColors'>setColors</a> </li>
<li class='toc3'><a href='#-font'>font</a> </li>
</ul><li class='toc2'><a href='#Inherited%20instance%20methods'>Inherited instance methods</a></li>
<li class='toc2'><a href='#Undocumented%20instance%20methods'>Undocumented instance methods</a></li>
<ul class='toc'><li class='toc3'><a href='#-initViews'>initViews</a> </li>
<li class='toc3'><a href='#-menu'>menu</a> </li>
</ul></ul><li class='toc1'><a href='#examples'>Examples</a></li>
<ul class='toc'></ul></ul></div><h2><a class='anchor' name='description'>Description</a></h2>
<p>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 <a href="./../Classes/EZGui.html">EZGui</a> and <a href="./../Classes/EZLists.html">EZLists</a> for all of the options.<h3><a class='anchor' name='Some%20Important%20Issues%20Regarding%20EZPopUpMenu'>Some Important Issues Regarding EZPopUpMenu</a></h3>
<p>The convenience methods for EZPopUpMenu require that the items array is an array of associations of labels and functions, not like in <a href="./../Classes/PopUpMenu.html">PopUpMenu</a>, where items is simply an array of strings. If <code class='code prettyprint lang-sc'>label</code> is <code class='code prettyprint lang-sc'>nil</code>, then no staticText is created.<h2><a class='anchor' name='classmethods'>Class Methods</a></h2>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*new' href='./../Overviews/Methods.html#new'>new</a> (<span class='argstr'>parentView</span>, <span class='argstr'>bounds</span>, <span class='argstr'>label</span>, <span class='argstr'>items</span>, <span class='argstr'>globalAction</span>, <span class='argstr'>initVal: 0</span>, <span class='argstr'>initAction: false</span>, <span class='argstr'>labelWidth</span>, <span class='argstr'>labelHeight: 20</span>, <span class='argstr'>layout</span>, <span class='argstr'>gap</span>, <span class='argstr'>margin</span>)</h3>
<div class='supmethod'>From superclass: <a href='./../Classes/EZLists.html'>EZLists</a></div>
<div class='method'>
<p><h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>parentView<td class='argumentdesc'>
<p>The parent view or window. If the parent is nil, then EZPopUpMenu will create its own <a href="./../Classes/Window.html">Window</a>, and place it conveniently on the screen if the bounds are a <a href="./../Classes/Point.html">Point</a>. If the bounds are a <a href="./../Classes/Rect.html">Rect</a>, then the <a href="./../Classes/Rect.html">Rect</a> determines the window bounds.<tr><td class='argumentname'>bounds<td class='argumentdesc'>
<p>An instance of <a href="./../Classes/Rect.html">Rect</a> or <a href="./../Classes/Point.html">Point</a>. Default value is <code class='code prettyprint lang-sc'>160@22</code>.<tr><td class='argumentname'>label<td class='argumentdesc'>
<p>The label. Default value is <code class='code prettyprint lang-sc'>nil</code>. If <code class='code prettyprint lang-sc'>nil</code>, then no <a href="./../Classes/StaticText.html">StaticText</a> is created.<tr><td class='argumentname'>items<td class='argumentdesc'>
<p>Default value is <code class='code prettyprint lang-sc'>nil</code>. An <a href="./../Classes/Array.html">Array</a> of <a href="./../Classes/Association.html">Association</a>s <code class='code prettyprint lang-sc'>['label' -&gt; { arg menuObj; value }, ]</code>. Or and <a href="./../Classes/Array.html">Array</a> <a href="./../Classes/Symbol.html">Symbol</a>s (if you are only using <code class='code prettyprint lang-sc'>globalAction</code>).<tr><td class='argumentname'>globalAction<td class='argumentdesc'>
<p>A global function to be performed in addition to the item functions <code class='code prettyprint lang-sc'>{ arg menuObj; value }</code>.<tr><td class='argumentname'>initVal<td class='argumentdesc'>
<p>Initial value of the menu, i.e. the index selected. Default value is 0.<tr><td class='argumentname'>initAction<td class='argumentdesc'>
<p>An instance of <a href="./../Classes/Boolean.html">Boolean</a>. Performs the action at <code class='code prettyprint lang-sc'>initVal</code> on creation of the menu, plus the <code class='code prettyprint lang-sc'>globalAction</code>. Default value is <code class='code prettyprint lang-sc'>false</code>.<tr><td class='argumentname'>labelWidth<td class='argumentdesc'>
<p>Default value is 80.<tr><td class='argumentname'>labelHeight<td class='argumentdesc'>
<p>Default value is 20. Not used if layout is <code class='code prettyprint lang-sc'>\horz</code>.<tr><td class='argumentname'>layout<td class='argumentdesc'>
<p><code class='code prettyprint lang-sc'>\vert</code> or <code class='code prettyprint lang-sc'>\horz</code>. default is <code class='code prettyprint lang-sc'>\horz</code>.<tr><td class='argumentname'>gap<td class='argumentdesc'>
<p>A <a href="./../Classes/Point.html">Point</a>. By default, the view tries to get its parent's <code class='code prettyprint lang-sc'>gap</code>, otherwise it defaults to <code class='code prettyprint lang-sc'>2@2</code>. Setting it overrides these.<tr><td class='argumentname'>margin<td class='argumentdesc'>
<p>A <a href="./../Classes/Point.html">Point</a>. This will inset the bounds occupied by the subviews of view.</table><h4>Discussion:</h4>
<pre class='code prettyprint lang-sc'>(
w = Window.new.front;
w.view.decorator = FlowLayout(w.view.bounds);
g = EZPopUpMenu.new(
w,
230@22,
"A PopUpMenu: ",
[
\item0 -&gt;{|a| ("this is item 0 of " ++ a).postln},
\item1 -&gt;{|a| ("this is item 1 of " ++ a).postln},
\item2 -&gt;{|a| ("this is item 2 of " ++ a).postln},
],
globalAction: {|a| ("this is a global action of "++a.asString ).postln},
initVal: 1,
initAction: true,
labelWidth: 120,
labelHeight: 20,
layout: \horz,
gap: 2@2
);
)
// or a more simple syntax:
(
w = Window.new.front;
w.view.decorator = FlowLayout(w.view.bounds);
g = EZPopUpMenu.new(w, 200@22, "Menu: ");
g.addItem(\item0, { |a| ("this is item 0 of " ++ a).postln });
g.addItem(\item1, { |a| ("this is item 1 of " ++ a).postln });
g.addItem(\item2, { |a| ("this is item 2 of " ++ a).postln });
g.value = 0;
)</pre>
</div><h3><a class='anchor' name='Inherited%20class%20methods'>Inherited class methods</a></h3>
<div id='inheritedclassmets'></div><h2><a class='anchor' name='instancemethods'>Instance Methods</a></h2>
<h3><a class='anchor' name='Changing%20Appearance'>Changing Appearance</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-setColors' href='./../Overviews/Methods.html#setColors'>setColors</a> (<span class='argstr'>stringBackground</span>, <span class='argstr'>stringColor</span>, <span class='argstr'>menuBackground</span>, <span class='argstr'>menuStringColor</span>, <span class='argstr'>background</span>)</h3>
<div class='method'><h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>stringBackground<td class='argumentdesc'>
<p>An instance of <a href="./../Classes/Color.html">Color</a>. The <code class='code prettyprint lang-sc'>background</code> of the label and unit views.<tr><td class='argumentname'>stringColor<td class='argumentdesc'>
<p>An instance of <a href="./../Classes/Color.html">Color</a>. The <code class='code prettyprint lang-sc'>stringColor</code> of the label and unit views.<tr><td class='argumentname'>menuBackground<td class='argumentdesc'>
<p>An instance of <a href="./../Classes/Color.html">Color</a>. The <code class='code prettyprint lang-sc'>background</code> of the menu.<tr><td class='argumentname'>menuStringColor<td class='argumentdesc'>
<p>An instance of <a href="./../Classes/Color.html">Color</a>. The <code class='code prettyprint lang-sc'>stringColor</code> of the menu.<tr><td class='argumentname'>background<td class='argumentdesc'>
<p>An instance of <a href="./../Classes/Color.html">Color</a>. The <code class='code prettyprint lang-sc'>background</code> of the list view.</table></div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-font' href='./../Overviews/Methods.html#font'>font</a> = <span class='argstr'>font</span></h3>
<div class='supmethod'>From superclass: <a href='./../Classes/EZGui.html'>EZGui</a></div>
<div class='method'>
<p>Set the <a href="./../Classes/Font.html">Font</a> used by all the views.<h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>font<td class='argumentdesc'>
<p>An instance of <a href="./../Classes/Font.html">Font</a>.</table></div><h3><a class='anchor' name='Inherited%20instance%20methods'>Inherited instance methods</a></h3>
<div id='inheritedinstmets'></div><h3><a class='anchor' name='Undocumented%20instance%20methods'>Undocumented instance methods</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-initViews' href='./../Overviews/Methods.html#initViews'>initViews</a> (<span class='argstr'>parentView</span>, <span class='argstr'>bounds</span>, <span class='argstr'>label</span>, <span class='argstr'>labelWidth</span>, <span class='argstr'>labelHeight</span>, <span class='argstr'>arglayout</span>)</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-menu' href='./../Overviews/Methods.html#menu'>menu</a> </h3>
<h2><a class='anchor' name='examples'>Examples</a></h2>
<pre class='code prettyprint lang-sc'>// try several examples together
(
// many menus
// inherits the parent's decorator gap
(
w=Window.new("oscillators", Rect(200,500,200,160)).front;
w.view.decorator = FlowLayout(w.view.bounds).gap_(2@2);
5.do{|i|
g = EZPopUpMenu.new(w,190@22, "Oscillator % : ".format(i+1));
g.addItem(\off, {"off". postln});
g.addItem(\sine, {"sine". postln});
g.addItem(\saw, {"saw". postln});
g.addItem(\pulse, {"pulse". postln});
g.setColors(Color.grey,Color.white);
g.value=0;
};
w.bounds=w.bounds.moveBy(300,60);
);
// Creates its own window if parentView is nil:
(
g = EZPopUpMenu.new(nil,250@22 ," Select : ");
g.addItem(\item0, {"this is item 0". postln});
g.addItem(\item1, {"this is item 1". postln});
g.addItem(\item2, {"this is item 2". postln});
g.setColors(Color.grey,Color.white);
g.value=0;
);
// layout vertical:
(
g = EZPopUpMenu.new(nil,200@42, " Choose",layout:\vert);
g.addItem(\item0, {"this is item 0". postln});
g.addItem(\item1, {"this is item 1". postln});
g.addItem(\item2, {"this is item 2". postln});
g.setColors(Color.grey,Color.white);
g.window.bounds=g.window.bounds.moveBy(300,-200);
g.value=0;
);
// No labelView created, so set the window title;
(
g = EZPopUpMenu.new(bounds:180@22); // no label
g.addItem(\item0, {"this is item 0". postln});
g.addItem(\item1, {"this is item 1". postln});
g.addItem(\item2, {"this is item 2". postln});
g.value=0;
g.window.name=" choose item";
g.window.bounds=g.window.bounds.moveBy(0,-200);
);
)
// insertItem;
(
g = EZPopUpMenu.new(nil,200@22, "Menu:");
g.addItem(\item0, {"this is item 0". postln});
g.addItem(\item1, {"this is item 1". postln});
g.addItem(\item2, {"this is item 2". postln});
g.addItem(\item4, {"this is item 4". postln});
g.value=0;
);
g.insertItem(3, \item3, {"this is item 3". postln});
// remove Item ;
(
w=Window.new.front;
w.view.decorator = FlowLayout(w.view.bounds);
g = EZPopUpMenu.new(w,200@22, "Menu:");
g.addItem(\item0, {"this is item 0". postln});
g.addItem(\item1, {"this is item 1". postln});
g.addItem(\item2, {"this is item 2". postln});
g.addItem(\item4, {"this is item 4". postln});
g.insertItem(3, \item3, {"this is item 3". postln});
g.value=0;
)
g. removeItemAt(0);
// replace item;
(
g = EZPopUpMenu.new(nil,200@22, "List:");
g.addItem(\item0, {"this is item 0". postln});
g.addItem(\item1, {"this is item 1". postln});
g.addItem(\item2, {"this is item 2". postln});
g.addItem(\item3, {"this is item 3". postln});
)
g.replaceItemAt(2, \item2_replaced, {"this is item 2 replaced". postln});</pre>
<p><div class='doclink'>helpfile source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/EZPopUpMenu.schelp'>/Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/EZPopUpMenu.schelp</a><br>link::Classes/EZPopUpMenu::<br>sc version: 3.8.0</div></div></body></html>