forked from sojamo/controlp5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControlP5scrollableList.pde
261 lines (240 loc) · 11.5 KB
/
ControlP5scrollableList.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
* ControlP5 ScrollableList
*
* replaces DropdownList and and ListBox.
* List can be scrolled by dragging the list or using the scroll-wheel.
*
* by Andreas Schlegel, 2014
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
import java.util.*;
ControlP5 cp5;
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
List l = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");
/* add a ScrollableList, by default it behaves like a DropdownList */
cp5.addScrollableList("dropdown")
.setPosition(100, 100)
.setSize(200, 100)
.setBarHeight(20)
.setItemHeight(20)
.addItems(l)
// .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST
;
}
void draw() {
background(240);
}
void dropdown(int n) {
/* request the selected item based on index n */
println(n, cp5.get(ScrollableList.class, "dropdown").getItem(n));
/* here an item is stored as a Map with the following key-value pairs:
* name, the given name of the item
* text, the given text of the item by default the same as name
* value, the given value of the item, can be changed by using .getItem(n).put("value", "abc"); a value here is of type Object therefore can be anything
* color, the given color of the item, how to change, see below
* view, a customizable view, is of type CDrawable
*/
CColor c = new CColor();
c.setBackground(color(255,0,0));
cp5.get(ScrollableList.class, "dropdown").getItem(n).put("color", c);
}
void keyPressed() {
switch(key) {
case('1'):
/* make the ScrollableList behave like a ListBox */
cp5.get(ScrollableList.class, "dropdown").setType(ControlP5.LIST);
break;
case('2'):
/* make the ScrollableList behave like a DropdownList */
cp5.get(ScrollableList.class, "dropdown").setType(ControlP5.DROPDOWN);
break;
case('3'):
/*change content of the ScrollableList */
List l = Arrays.asList("a-1", "b-1", "c-1", "d-1", "e-1", "f-1", "g-1", "h-1", "i-1", "j-1", "k-1");
cp5.get(ScrollableList.class, "dropdown").setItems(l);
break;
case('4'):
/* remove an item from the ScrollableList */
cp5.get(ScrollableList.class, "dropdown").removeItem("k-1");
break;
case('5'):
/* clear the ScrollableList */
cp5.get(ScrollableList.class, "dropdown").clear();
break;
}
}
/*
a list of all methods available for the ScrollableList Controller
use ControlP5.printPublicMethodsFor(ScrollableList.class);
to print the following list into the console.
You can find further details about class ScrollableList in the javadoc.
Format:
ClassName : returnType methodName(parameter type)
controlP5.Controller : CColor getColor()
controlP5.Controller : ControlBehavior getBehavior()
controlP5.Controller : ControlWindow getControlWindow()
controlP5.Controller : ControlWindow getWindow()
controlP5.Controller : ControllerProperty getProperty(String)
controlP5.Controller : ControllerProperty getProperty(String, String)
controlP5.Controller : ControllerView getView()
controlP5.Controller : Label getCaptionLabel()
controlP5.Controller : Label getValueLabel()
controlP5.Controller : List getControllerPlugList()
controlP5.Controller : Pointer getPointer()
controlP5.Controller : ScrollableList addCallback(CallbackListener)
controlP5.Controller : ScrollableList addListener(ControlListener)
controlP5.Controller : ScrollableList addListenerFor(int, CallbackListener)
controlP5.Controller : ScrollableList align(int, int, int, int)
controlP5.Controller : ScrollableList bringToFront()
controlP5.Controller : ScrollableList bringToFront(ControllerInterface)
controlP5.Controller : ScrollableList hide()
controlP5.Controller : ScrollableList linebreak()
controlP5.Controller : ScrollableList listen(boolean)
controlP5.Controller : ScrollableList lock()
controlP5.Controller : ScrollableList onChange(CallbackListener)
controlP5.Controller : ScrollableList onClick(CallbackListener)
controlP5.Controller : ScrollableList onDoublePress(CallbackListener)
controlP5.Controller : ScrollableList onDrag(CallbackListener)
controlP5.Controller : ScrollableList onDraw(ControllerView)
controlP5.Controller : ScrollableList onEndDrag(CallbackListener)
controlP5.Controller : ScrollableList onEnter(CallbackListener)
controlP5.Controller : ScrollableList onLeave(CallbackListener)
controlP5.Controller : ScrollableList onMove(CallbackListener)
controlP5.Controller : ScrollableList onPress(CallbackListener)
controlP5.Controller : ScrollableList onRelease(CallbackListener)
controlP5.Controller : ScrollableList onReleaseOutside(CallbackListener)
controlP5.Controller : ScrollableList onStartDrag(CallbackListener)
controlP5.Controller : ScrollableList onWheel(CallbackListener)
controlP5.Controller : ScrollableList plugTo(Object)
controlP5.Controller : ScrollableList plugTo(Object, String)
controlP5.Controller : ScrollableList plugTo(Object[])
controlP5.Controller : ScrollableList plugTo(Object[], String)
controlP5.Controller : ScrollableList registerProperty(String)
controlP5.Controller : ScrollableList registerProperty(String, String)
controlP5.Controller : ScrollableList registerTooltip(String)
controlP5.Controller : ScrollableList removeBehavior()
controlP5.Controller : ScrollableList removeCallback()
controlP5.Controller : ScrollableList removeCallback(CallbackListener)
controlP5.Controller : ScrollableList removeListener(ControlListener)
controlP5.Controller : ScrollableList removeListenerFor(int, CallbackListener)
controlP5.Controller : ScrollableList removeListenersFor(int)
controlP5.Controller : ScrollableList removeProperty(String)
controlP5.Controller : ScrollableList removeProperty(String, String)
controlP5.Controller : ScrollableList setArrayValue(float[])
controlP5.Controller : ScrollableList setArrayValue(int, float)
controlP5.Controller : ScrollableList setBehavior(ControlBehavior)
controlP5.Controller : ScrollableList setBroadcast(boolean)
controlP5.Controller : ScrollableList setCaptionLabel(String)
controlP5.Controller : ScrollableList setColor(CColor)
controlP5.Controller : ScrollableList setColorActive(int)
controlP5.Controller : ScrollableList setColorBackground(int)
controlP5.Controller : ScrollableList setColorCaptionLabel(int)
controlP5.Controller : ScrollableList setColorForeground(int)
controlP5.Controller : ScrollableList setColorLabel(int)
controlP5.Controller : ScrollableList setColorValue(int)
controlP5.Controller : ScrollableList setColorValueLabel(int)
controlP5.Controller : ScrollableList setDecimalPrecision(int)
controlP5.Controller : ScrollableList setDefaultValue(float)
controlP5.Controller : ScrollableList setHeight(int)
controlP5.Controller : ScrollableList setId(int)
controlP5.Controller : ScrollableList setImage(PImage)
controlP5.Controller : ScrollableList setImage(PImage, int)
controlP5.Controller : ScrollableList setImages(PImage, PImage, PImage)
controlP5.Controller : ScrollableList setImages(PImage, PImage, PImage, PImage)
controlP5.Controller : ScrollableList setLabel(String)
controlP5.Controller : ScrollableList setLabelVisible(boolean)
controlP5.Controller : ScrollableList setLock(boolean)
controlP5.Controller : ScrollableList setMax(float)
controlP5.Controller : ScrollableList setMin(float)
controlP5.Controller : ScrollableList setMouseOver(boolean)
controlP5.Controller : ScrollableList setMoveable(boolean)
controlP5.Controller : ScrollableList setPosition(float, float)
controlP5.Controller : ScrollableList setPosition(float[])
controlP5.Controller : ScrollableList setSize(PImage)
controlP5.Controller : ScrollableList setSize(int, int)
controlP5.Controller : ScrollableList setStringValue(String)
controlP5.Controller : ScrollableList setUpdate(boolean)
controlP5.Controller : ScrollableList setValue(float)
controlP5.Controller : ScrollableList setValueLabel(String)
controlP5.Controller : ScrollableList setValueSelf(float)
controlP5.Controller : ScrollableList setView(ControllerView)
controlP5.Controller : ScrollableList setVisible(boolean)
controlP5.Controller : ScrollableList setWidth(int)
controlP5.Controller : ScrollableList show()
controlP5.Controller : ScrollableList unlock()
controlP5.Controller : ScrollableList unplugFrom(Object)
controlP5.Controller : ScrollableList unplugFrom(Object[])
controlP5.Controller : ScrollableList unregisterTooltip()
controlP5.Controller : ScrollableList update()
controlP5.Controller : ScrollableList updateSize()
controlP5.Controller : String getAddress()
controlP5.Controller : String getInfo()
controlP5.Controller : String getName()
controlP5.Controller : String getStringValue()
controlP5.Controller : String toString()
controlP5.Controller : Tab getTab()
controlP5.Controller : boolean isActive()
controlP5.Controller : boolean isBroadcast()
controlP5.Controller : boolean isInside()
controlP5.Controller : boolean isLabelVisible()
controlP5.Controller : boolean isListening()
controlP5.Controller : boolean isLock()
controlP5.Controller : boolean isMouseOver()
controlP5.Controller : boolean isMousePressed()
controlP5.Controller : boolean isMoveable()
controlP5.Controller : boolean isUpdate()
controlP5.Controller : boolean isVisible()
controlP5.Controller : float getArrayValue(int)
controlP5.Controller : float getDefaultValue()
controlP5.Controller : float getMax()
controlP5.Controller : float getMin()
controlP5.Controller : float getValue()
controlP5.Controller : float[] getAbsolutePosition()
controlP5.Controller : float[] getArrayValue()
controlP5.Controller : float[] getPosition()
controlP5.Controller : int getDecimalPrecision()
controlP5.Controller : int getHeight()
controlP5.Controller : int getId()
controlP5.Controller : int getWidth()
controlP5.Controller : int listenerSize()
controlP5.Controller : void remove()
controlP5.Controller : void setView(ControllerView, int)
controlP5.ScrollableList : List getItems()
controlP5.ScrollableList : Map getItem(String)
controlP5.ScrollableList : Map getItem(int)
controlP5.ScrollableList : ScrollableList addItem(String, Object)
controlP5.ScrollableList : ScrollableList addItems(List)
controlP5.ScrollableList : ScrollableList addItems(Map)
controlP5.ScrollableList : ScrollableList addItems(String[])
controlP5.ScrollableList : ScrollableList clear()
controlP5.ScrollableList : ScrollableList close()
controlP5.ScrollableList : ScrollableList open()
controlP5.ScrollableList : ScrollableList removeItem(String)
controlP5.ScrollableList : ScrollableList removeItems(List)
controlP5.ScrollableList : ScrollableList setBackgroundColor(int)
controlP5.ScrollableList : ScrollableList setBarHeight(int)
controlP5.ScrollableList : ScrollableList setBarVisible(boolean)
controlP5.ScrollableList : ScrollableList setItemHeight(int)
controlP5.ScrollableList : ScrollableList setItems(List)
controlP5.ScrollableList : ScrollableList setItems(Map)
controlP5.ScrollableList : ScrollableList setItems(String[])
controlP5.ScrollableList : ScrollableList setOpen(boolean)
controlP5.ScrollableList : ScrollableList setScrollSensitivity(float)
controlP5.ScrollableList : ScrollableList setType(int)
controlP5.ScrollableList : boolean isBarVisible()
controlP5.ScrollableList : boolean isOpen()
controlP5.ScrollableList : int getBackgroundColor()
controlP5.ScrollableList : int getBarHeight()
controlP5.ScrollableList : int getHeight()
controlP5.ScrollableList : void controlEvent(ControlEvent)
controlP5.ScrollableList : void keyEvent(KeyEvent)
controlP5.ScrollableList : void setDirection(int)
controlP5.ScrollableList : void updateItemIndexOffset()
java.lang.Object : String toString()
java.lang.Object : boolean equals(Object)
created: 2015/03/24 12:21:22
*/