ControlP5: Autopositioning of controls / controlgroups
in
Contributed Library Questions
•
1 year ago
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:
- public Button addButton(String theName, float theValue) {
- Button b = addButton(theName, theValue, (int) currentGroupPointer.autoPosition.x, (int) currentGroupPointer.autoPosition.y, Button.autoWidth, Button.autoHeight);
- linebreak(b, false, Button.autoWidth, Button.autoHeight, b.autoSpacing);
- b.moveTo(currentGroupPointer);
- return b;
Here's my (simplified) code - you hit 'Create', then 'Reset', then 'Create' again:
- import controlP5.*;
- ControlP5 controlP5;
- void setup() {
- size(600,400);
- controlP5 = new ControlP5(this);
- controlP5.addButton("Create", 1);
- controlP5.addButton("Reset", 1).linebreak();
- }
- void draw (){
- background(0);
- }
- void Create (){
- for(int i = 1; i < 40; i++){
- String buttonname = str(i);
- if (i%7 <= 0 && i != 0) {
- controlP5.addButton(buttonname, i).linebreak();
- } else {
- controlP5.addButton(buttonname, i);
- }
- }
- }
- void Reset (){
- for(int i = 1; i < 40; i++){
- String buttonname = str(i);
- controlP5.controller(buttonname).remove();
- }
- }
1