scide: implement selectionLength for openDocument
[supercollider.git] / HelpSource / Classes / PopUpMenu.schelp
blob2a2ec9f7acb2a3ebe2f895c2d65fdb8e31004e3d
1 CLASS:: PopUpMenu
2 redirect:: implClass
3 summary:: A view displaying a text item selectable from a drop-down menu.
4 categories:: GUI>Views
6 DESCRIPTION::
8 When clicked, this view opens a menu containing several text items, then closes the menu and displays one of the items after it is selected.
10 CLASSMETHODS::
12 PRIVATE:: key
17 INSTANCEMETHODS::
21 SUBSECTION:: Data
23 METHOD:: items
24         The list of items displayed in a menu when the view is clicked.
26         argument::
27                 An Array of Strings or Symbols.
29 METHOD:: item
30         The currently selected item.
32         returns::
33                 A String.
35 METHOD:: value
36         The index of the currently selected item.
38         argument::
39                 An integer, or nil meaning no selected item.
41 METHOD:: valueAction
42         Sets link::#-value:: and triggeres link::#-action::.
44         argument::
45                 An integer, or nil meaning no selected item.
49 SUBSECTION:: Appearance
51 METHOD:: stringColor
52         The color used to display text.
54         argument::
55                 A Color.
57 METHOD:: background
58         Setting this variable colors the area of the view under the text with the given color.
60         argument::
61                 A Color.
65 SUBSECTION:: Interaction
67 METHOD:: allowsReselection
68         Determines whether the action is triggered when selecting already selected item. Defaults to false.
70         argument::
71                 A Boolean.
75 SUBSECTION:: Actions
77 METHOD:: action
78         The action object evaluated whenever the user changes the selected item from the menu. See link::#-allowsReselection:: for customization.
82 SUBSECTION:: Drag and drop
84 METHOD:: defaultGetDrag
85         returns::
86                 The link::#-value::.
88 METHOD:: defaultCanReceiveDrag
89         returns::
90                 True if the current drag data is a number.
92 METHOD:: defaultReceiveDrag
93         Sets link::#-valueAction:: to the current drag data.
97 EXAMPLES::
99 subsection:: Basic Example
101 code::
103 w = Window.new("The Eightfold Path").front;
104 m = PopUpMenu(w,Rect(10,10,180,20));
106 m.items = [
107     "right view","right thinking","right mindfulness","right speech",
108     "right action","right diligence","right concentration","right livelihood"
111 m.background_(Color.green(0.7));        // only changes the look of displayed item
112 m.stringColor_(Color.white);            // only changes the look of displayed item
113 m.font_(Font("Courier", 13));           // only changes the look of displayed item
114 m.action = { arg menu;
115     [menu.value, menu.item].postln;
119 m.value;            // returns the index of the current item;
120 m.item;             // returns the String or Symbol of the current item
122 m.value_(2);        // changes the displayed item, but does not evaluate the action
123 m.valueAction_(3);  // evaluates the action.
126 subsection:: Sound Example
128 Play different functions:
130 code::
132 s.waitForBoot({
134     var w,menu,snd,funcs,b;
136     w=Window.new.front;
138     menu=PopUpMenu(w,Rect(10,10,90,20))
139         .items_(["Sine" , "Saw" , "Noise" , "Pulse"]);
141     funcs=[
142         {SinOsc.ar(440,0,0.3)},
143         {Saw.ar(440,0.3)},
144         {WhiteNoise.ar(0.3)},
145         {Pulse.ar(440,0.2,0.3)}
146     ];
148     b=Button(w,Rect(110,10,180,20))
149         .states_([["play",Color.black,Color.green]])
150         .mouseDownAction_({
151                 snd = funcs.at(menu.value).play;
152             })
153         .action_({ arg butt, mod;
154                 snd.free;
155             });
157     w.front;
159     p=CmdPeriod.add({b.value_(0)}); // set button to 0 on hitting Cmd-period
160     w.onClose_{ snd.free; CmdPeriod.removeAll }; // clean up when window is closed