setVisible(false) cause myButtons to stop working

edited May 12 in Library Questions

Good aftenoon. First, sorry for my poor english !

I have an issue with my ControlP5 Buttons. I'm using a "Window" class, wich contains (among other stuff) an arrayList of Button. When i change the current window, I want to hide the previous buttons and show the buttons of the new window. Of course i'm using .setVisible(boolean), but apparently, doing so cause my "new" buttons to not work properly.

Here is the location in the code where I found the problem: for(i = 0; i < listeBoutons.size(); i++){ listeBoutons.get(i).setVisible(false); }

for(i = 0; i < fenetreActive.boutons.size(); i++){ fenetreActive.boutons.get(i).setVisible(true); }

"listeBoutons" is my ArrayList which contains ALL the Buttons of my application (I need this elsewhere). I'm lazzy, so I basically try to make all the buttons invisible THEN using fenetreActive (which is my "window") acces to the Buttons of the new windows and make them visible. It's a harsh way to proceed but seems to work : all my button have the correct .isVisible() state (i've check by printing some tracks with .getInfo() )

If I use JUST the second loop, as expected when I change the window, new buttons appears and the "old" stay on the screen. Every single one of them work PERFECTLY fine in that case. But, if i add the first loop, in charge of "removing" the old buttons from my screen... they do disapear... but the new ones are not functional. Weird thing is : the new buttons appear on screen (with correct text, size etc...) but won't react to any Event.

I'm a bit lost. My program is working as if, by hidding my Buttons, I had disabled them all.

Here is a sample of my controlEvent function :

void controlEvent(ControlEvent event){ println("Event received from" + event.getName()); if(event.getName().equals("Begin")){ changeWindow("Menus"); } else if(event.getName().equals("OtherName")){ println("something"); } //Etc... } }

I'm not used to work with ControlP5, so my understanding of the problem may be wronged. It would be great if someone could explain to me what the problem really is !

Answers

  • Answer ✓

    If you make a button invisible then it will also be disabled

    If you make a button visible it will NOT change its enabled/disabled state. So when you make the button visible again you MUST also enable it.

  • edited May 12

    Well that certainely helps, thank you ! However i'm confused because I dont find in the documentation anything like ".enable()" or similar. Hence my confusion it is not stated anywhere (that I can find) that making button invisible do both things... and nothing about how to reverse it !

  • edited May 12

    I am not familiar with using cpntrolP5 but if you think about it it is logical.

    A button has the boolean properties
    1) visible
    2) enabled

    When you create a button they are both set to true. Now if you make a control invisible (visible == false) then controlP5 also sets the enabled to false. If it didn't then clicking on where the button was showing would trigger the button's event - not desirable.

    When you make the button visible again (visible == true) controlP5 does not change the enabled property. controlP5 cannot assume that you want the button enabled just because you made it visible.

    This is standard behaviour for all GUIs.

Sign In or Register to comment.