ControlP5: How to create a group of controllers that appear/disappear when clicking a button.
in
Contributed Library Questions
•
11 months ago
So I'm pretty new to CP5 and so far I like how much time it can save me with laying controllers out. I'd like to become a little more adept with it though. Right now I am having trouble getting a button press event to show or hide a CP5 group.
I started this out by declaring a CP5 group and setting it's visibility to false. The groups visibility will turn to true when a button with the appropriate id is clicked.... However, I am getting a strange error whenever I click on the button, regardless of whether or not the group is visible at the point or not (I've tried turning it visible just to make sure it's where I want it.)
Here are the relevant code pieces (they do not share the same function span):
Group g1 = cp5.addGroup("g1")
.setPosition(firstFilterTabPlotX - (scaleFactor * 130), firstFilterTabPlotY)
.setBackgroundHeight(200)
.setBackgroundColor(color(240, 90))
.setVisible(false)
;
cp5.addButton("Driver\nVariables", 1)
.setId(3)
.setPosition(firstFilterTabPlotX, firstFilterTabPlotY)
.setSize(scaleFactor * 70, scaleFactor * 35)
.getCaptionLabel().align(CENTER, TOP);
public void controlEvent(ControlEvent theEvent) {
switch(theEvent.getController().getId()) {
case(1):
graphIsShown = false;
mapIsShown = true;
break;
case(2):
mapIsShown = false;
graphIsShown = true;
break;
case(3):
cp5.getController("g1")
.setVisible(true);
break;
}
}
Also, I'd like to better understand how to get CP5 objects to talk to one another, can anyone tell me what plugTo() or setBroadcast() does? In what situations would I need to use either of these? I've tried the plugTo() example included in the cp5 library but the sketch is so similar to every other cp5 example sketch that I can't discern plugTo()'s it's utility.
Thank you!
1