Loading...
Logo
Processing Forum
I have a sketch that iteratively creates controls using addButton, which works great.

I want to remove these buttons and replace them with new ones, but after they are removed ControlP5 automatically positions them after the original buttons.  I checked ControlP5Base.java and I think I can see where this is happening:
Copy code
  1. public Button addButton(String theName, float theValue) {
  2. Button b = addButton(theName, theValue, (int) currentGroupPointer.autoPosition.x, (int) currentGroupPointer.autoPosition.y, Button.autoWidth, Button.autoHeight);
  3. linebreak(b, false, Button.autoWidth, Button.autoHeight, b.autoSpacing);
  4. b.moveTo(currentGroupPointer);
  5. return b;
however I can't figure out how to reset currentGroupPointer.autoPosition.*

Here's my (simplified) code - you hit 'Create', then 'Reset', then 'Create' again:

Copy code
  1. import controlP5.*;

  2. ControlP5 controlP5;

  3. void setup() {
  4.   size(600,400);
  5.   controlP5 = new ControlP5(this);
  6.   controlP5.addButton("Create", 1);
  7.   controlP5.addButton("Reset", 1).linebreak();
  8. }

  9. void draw (){
  10.   background(0);
  11. }

  12. void Create (){
  13.   for(int i = 1; i < 40; i++){
  14.   String buttonname = str(i);
  15.   if (i%7 <= 0 && i != 0) {
  16.   controlP5.addButton(buttonname, i).linebreak();
  17.   } else {
  18.     controlP5.addButton(buttonname, i);
  19.   }
  20.   }
  21. }

  22. void Reset (){
  23.   for(int i = 1; i < 40; i++){
  24.   String buttonname = str(i);
  25.       controlP5.controller(buttonname).remove();
  26.   }
  27. }

Replies(6)

Found it - somehow missed the ControlP5auto example completely!
Copy code
  1.   // begin a new group of auto-arranged controllers
  2.   controlP5.begin(10,10);
hi, don't forget to close the auto-arranged group of controllers with 
Copy code
  1. controlP5.end();

Thanks Andreas, and  thanks a lot for the library 
can you not add control groups to a P5control window?
Without wanting to sound dismissive, what would be the advantage of that?  Are all groups collapsible or is that just the in the example (controlp5group.pde)?
yeah they are meant to be, but if you add them to a new window theyre not responsive and useless