ControlP5 listbox loses mouseclicks
in
Contributed Library Questions
•
3 years ago
I'm having a problem with listBox stealing mouse clicks from my program. I made a simple example to show this. I didn't have this problem when I was using the older scrollList, but it seems to exist in listBox...
I am attaching the controlP5 website example for using ListBox. I added a few lines to controlEvent() to set the label of the listbox after it is selected, and then automatically close it up. This part works fine, but then the next mouse click is always stolen, it doesn't re-open the listBox, or if you had any other controllers on the screen, it doesn't activate them. Wondering if this is a bug or there is something I'm doing wrong?
thanks!
/**
* ControlP5 ListBox
* listBox operates the same way as a scrollList, but
* is optimized for many items (1000+). using a listBox
* over a scrollList is recommended
* by andreas schlegel, 2009
*/
import controlP5.*;
ControlP5 controlP5;
ListBox l;
int cnt = 0;
void setup() {
size(400,400);
frameRate(30);
controlP5 = new ControlP5(this);
l = controlP5.addListBox("myList",100,100,120,120);
l.setItemHeight(15);
l.setBarHeight(15);
l.captionLabel().toUpperCase(true);
l.captionLabel().set("something else");
l.captionLabel().style().marginTop = 3;
l.valueLabel().style().marginTop = 3; // the +/- sign
//l.setBackgroundColor(color(100,0,0));
for(int i=0;i<80;i++) {
l.addItem("item "+i,i);
}
l.setColorBackground(color(255,128));
l.setColorActive(color(0,0,255,128));
}
void keyPressed() {
if(key=='1') {
// set the height of a listBox should alwyays be a multiple of itemHeight
l.setHeight(210);
}
else if(key=='2') {
// set the height of a listBox should alwyays be a multiple of itemHeight
l.setHeight(120);
}
else if(key=='i') {
// set the height of a listBoxItem, should alwyays be a fraction of the listBox
l.setItemHeight(30);
}
else if(key=='u') {
// set the height of a listBoxItem, should alwyays be a fraction of the listBox
l.setItemHeight(10);
l.setBackgroundColor(color(100,0,0));
}
else if(key=='a') {
int n = (int)(random(100000));
l.addItem("item "+n, n);
}
else if(key=='d') {
l.removeItem("item "+cnt);
cnt++;
}
}
void controlEvent(ControlEvent theEvent) {
// ListBox is if type ControlGroup.
// 1 controlEvent will be executed, where the event
// originates from a ControlGroup. therefore
// you need to check the Event with
// if (theEvent.isGroup())
// to avoid an error message from controlP5.
if (theEvent.isGroup()) {
// an event from a group e.g. scrollList
println(theEvent.group().value()+" from "+theEvent.group());
l.setLabel("set to " + l.value());
l.close();
}
}
void draw() {
background(128);
// scroll the scroll List according to the mouseX position
// when holding down SPACE.
if(keyPressed && key==' ') {
//l.scroll(mouseX/((float)width)); // scroll taks values between 0 and 1
}
if(keyPressed && key==' ') {
l.setWidth(mouseX);
}
}
I am attaching the controlP5 website example for using ListBox. I added a few lines to controlEvent() to set the label of the listbox after it is selected, and then automatically close it up. This part works fine, but then the next mouse click is always stolen, it doesn't re-open the listBox, or if you had any other controllers on the screen, it doesn't activate them. Wondering if this is a bug or there is something I'm doing wrong?
thanks!
/**
* ControlP5 ListBox
* listBox operates the same way as a scrollList, but
* is optimized for many items (1000+). using a listBox
* over a scrollList is recommended
* by andreas schlegel, 2009
*/
import controlP5.*;
ControlP5 controlP5;
ListBox l;
int cnt = 0;
void setup() {
size(400,400);
frameRate(30);
controlP5 = new ControlP5(this);
l = controlP5.addListBox("myList",100,100,120,120);
l.setItemHeight(15);
l.setBarHeight(15);
l.captionLabel().toUpperCase(true);
l.captionLabel().set("something else");
l.captionLabel().style().marginTop = 3;
l.valueLabel().style().marginTop = 3; // the +/- sign
//l.setBackgroundColor(color(100,0,0));
for(int i=0;i<80;i++) {
l.addItem("item "+i,i);
}
l.setColorBackground(color(255,128));
l.setColorActive(color(0,0,255,128));
}
void keyPressed() {
if(key=='1') {
// set the height of a listBox should alwyays be a multiple of itemHeight
l.setHeight(210);
}
else if(key=='2') {
// set the height of a listBox should alwyays be a multiple of itemHeight
l.setHeight(120);
}
else if(key=='i') {
// set the height of a listBoxItem, should alwyays be a fraction of the listBox
l.setItemHeight(30);
}
else if(key=='u') {
// set the height of a listBoxItem, should alwyays be a fraction of the listBox
l.setItemHeight(10);
l.setBackgroundColor(color(100,0,0));
}
else if(key=='a') {
int n = (int)(random(100000));
l.addItem("item "+n, n);
}
else if(key=='d') {
l.removeItem("item "+cnt);
cnt++;
}
}
void controlEvent(ControlEvent theEvent) {
// ListBox is if type ControlGroup.
// 1 controlEvent will be executed, where the event
// originates from a ControlGroup. therefore
// you need to check the Event with
// if (theEvent.isGroup())
// to avoid an error message from controlP5.
if (theEvent.isGroup()) {
// an event from a group e.g. scrollList
println(theEvent.group().value()+" from "+theEvent.group());
l.setLabel("set to " + l.value());
l.close();
}
}
void draw() {
background(128);
// scroll the scroll List according to the mouseX position
// when holding down SPACE.
if(keyPressed && key==' ') {
//l.scroll(mouseX/((float)width)); // scroll taks values between 0 and 1
}
if(keyPressed && key==' ') {
l.setWidth(mouseX);
}
}
1