Loading...
Logo
Processing Forum
Is there any way to temporarily disable/enable GUI elements in ControlP5?

I guess it could be achieved with tabs, but in some situations it would make sense to have the option to make controllers inactive the same way Windows grays out buttons that are inactive. Or am I missing something?

I'm also missing more convenience methods to retrieve Buttons, Sliders etc. by ID, name etc. getControllerList() works but requires post-processing and type-casting. Functions like getButton(id), getSlider(id), getAllButtons() and getAllSliders() would be very useful.

Otherwise I'd like to express my great gratitude to Andreas for building this, if you add a Donate button I'd happily send you money for a beer...

Replies(5)

I usually set the draw off by default for all my controls and then only draw them as needed.
controlP5.setAutoDraw(false);

Then to active it I just do something like this..
if (drawcontrol) {
      controlP5.draw();
}

I also think there is an option for setVisible() on the controller.
I also group my controls.. creating many instances of controlP5, so not all my elements are draw by one control.
Thanks for the reply! But even if it works that sounds like a clunky solution, as you essentially disable ControlP5 itself rather than the individual controllers of interest.

Grouping sounds like a good strategy, though. I haven't bothered with that so far.
hi marius, to temporarily disable a button use the setLock function on a Controller like in the following

Copy code
  1. import controlP5.*;

  2. ControlP5 controlP5;
  3. int col;

  4. void setup() {
  5.   size(640,480);
  6.   smooth();
  7.   frameRate(30);
  8.   controlP5 = new ControlP5(this);
  9.   controlP5.addButton("buttonA",0,100,100,80,19);
  10.   controlP5.addButton("buttonB",255,100,120,80,19);
  11.   controlP5.addButton("buttonC",128,100,140,80,19);
  12.   
  13.   // store the original background color, we gonna need it later
  14.   col = controlP5.getController("buttonC").getColor().getBackground();
  15.   // lock Controller 'buttonC'
  16.   setLock(controlP5.getController("buttonC"),true);
  17. }


  18. void setLock(Controller theController, boolean theValue) {
  19.   theController.setLock(theValue);
  20.   if(theValue) {
  21.     theController.setColorBackground(color(100,100));
  22.   } else {
  23.     theController.setColorBackground(color(col));
  24.   }
  25. }

  26. void keyPressed() {
  27.   // temporarily enable/disable Controller 'buttonC'
  28.   if(key=='1') {
  29.     setLock(controlP5.getController("buttonC"), false);
  30.   } else if(key=='2') {
  31.     setLock(controlP5.getController("buttonC"), true);
  32.   }
  33. }

  34. void draw() {
  35.   background(0);
  36. }

  37. public void controlEvent(ControlEvent theEvent) {
  38.   println(theEvent.controller().name());
  39. }

 
Otherwise I'd like to express my great gratitude to Andreas for building this, if you add a Donate button I'd happily send you money for a beer...

:) ja, that donate button. it's coming ...


let me think about the other convenience methods you are mentioning, for now they are not in place, so i guess  getControllerList or getController is still the way to go.





Thanks Andreas, setLock() does the trick. Your sample code says "getController" when it should be "controller", though. I'm serious about the Donate button, btw!

Re: convenience methods: I think methods like getButtons() and getSliders() would save users a lot of type-casting or "if instanceof Button" type statements. A simpler option might be a getController(Class theClass) to save you from having a dozen different getXXX() methods.

Also, I sometimes change the name of my buttons on the fly so that using the controller(theName) function becomes difficult. A controller(int theID) would make sense.