Change properties of every controller of a group at once in controlP5

edited February 2017 in Library Questions

Is there an option to change properties of every controller of a Group at once? Say for example setLabelVisible(false) for every controller of a group by calling the method within the function invoked by an other controller's change event?

Answers

  • I am not sure about working with groups in controlP5. One way to do what you are asking for:

    cp5 = new ControlP5(this);
    cp5.addListBox("myList")
      .setPosition(600, 40)
      .setSize(140, 350)
      .setItemHeight(40)
      .setBarHeight(40)
      .setColorBackground(color(0, 102, 153))
      .setColorActive(color(0, 153, 50))
      .setColorForeground(color(255, 100, 0));
    

    and then you could do either cp5.hide() or cp5.show()

    Kf

  • @kfrajer So something like cp5.setColorActive(color) will affect all the items attached to it?

  • @Lord_of_the_Galaxy Not sure. I doubt it. Each controller will have their own color settings. This works for the OP's question because each controller is associated to a controlP5 object. If one needs to hide controllers in groups, you could have different controlP5 objects in your sketch and hide or show them at your convenience. I have to say I am not totally familiar with this library. I believe there is also a group option, or group behavior. I have seen it for option buttons but not sure if it will work with other controllers.

    Kf

  • Hi, if you change the colors of a group after you have added controllers to it, these controllers will change their colors accordingly, see example below

    import controlP5.*;
    
    ControlP5 cp5;
    
    void setup() {
      size(800,600);
      cp5 = new ControlP5(this);  
      Group a = cp5.addGroup("a").setPosition(40,40);
    
      cp5.addSlider("s1").setPosition(0,10).setValue(50).setSize(200,20).setGroup(a);
      cp5.addButton("b1").setPosition(0,40).setGroup(a);
    
      a.setColorForeground(color(255,0,0));
      a.setColorBackground(color(255,128,0));
      a.setColorActive(color(255,255,0));
      a.setColorLabel(color(150,0,0));
      a.setColorValue(color(150,0,0));
    
    }
    
    
    void draw() {
      background(200);
    }
    
Sign In or Register to comment.