Hi there,
quick question: is there a way to iterate over all the controls I have added to my controlP5? It seems like the only way to get a controller is by using controlP5.controle("nameOfTheController");
another question... I have a class where I dynamically add controllers. But somehow when I click a controller a event is triggered multiple times. Here's a code example. My problem is that when I use a slider (with just 1 click) my controlEvent is triggered multiple times... how's that possible?
Thanks in advance!
- import controlP5.*;
- ControlP5 controlP5;
- Letter[] letters;
- void setup() {
- size(800, 500);
- controlP5 = new ControlP5(this);
- letters = new Letter[0];
- Letter l = new Letter("A", controlP5);
- l.addFold(1);
- l.addFold(2);
- letters = (Letter[]) append(letters, l);
- Letter l2 = new Letter("B", controlP5);
- l2.addFold(1);
- l2.addFold(2);
- l2.addFold(3);
- l2.addFold(4);
- letters = (Letter[]) append(letters, l2);
- }
- void draw(){
- background(255);
- letters[1].showControlGroups();
- }
- void controlEvent(ControlEvent theEvent) {
- int foldNumber = theEvent.controller().parent().id()-1;
- println(foldNumber);
- }
- class Letter {
- String name;
- ControlP5 controlP5;
- ControlGroup[] cGroups;
- Letter(String name, ControlP5 p) {
- this.name = name;
- controlP5 = p;
- cGroups = new ControlGroup[0];
- }
- void addFold(int i) {
- ControlGroup g = controlP5.addGroup(name + " segment "+i, 20, -15 + i*45);
- g.setLabel("Segment "+i);
- g.setId(i);
- Slider s1 = controlP5.addSlider(name + " angle "+i, 0.001, 360, 100, 20, 0, 100, 10);
- s1.setId(1);
- s1.setColorLabel(0xff000000);
- s1.setCaptionLabel("Angle");
- s1.setGroup(g);
- Slider s2 = controlP5.addSlider(name + " length "+i, 0, 15, 10, 20, 15, 100, 10);
- s2.setId(2);
- s2.setColorLabel(0xff000000);
- s2.setGroup(g);
- s2.setCaptionLabel("Length");
- g.disableCollapse();
- g.hide();
- cGroups = (ControlGroup[]) append(cGroups, g);
- }
- void showControlGroups() {
- for (int i=0; i<cGroups.length; i++) {
- ControlGroup g = cGroups[i];
- g.show();
- }
- }
- }
1