ChildWindow close

Started by roccio, 01 October 2021, 12:06:05



I have a question regarding the ChildWindow CLOSE event in 0.9.
In the previous version of TGUI what I used to do is to create a childwindow at the start and then using setVisible member to show/hide it. The window is created with the Close button on the title bar. In the ONCLOSE event I set the visible attribute to false.
Now, on 0.9 I do the same thing, but the when  I show the window and use the close button, I am unable to show it again.

I tried using the onEscapeKeyPress event and in this case all works fine.

Do I need to do something else when using the onClose event?




The behavior in TGUI 0.8 was too surprising for a lot of people so it was changed to a new system.

When the close button is pressed, onClosing event is triggered which has a boolean as parameter that you can set to true to prevent the window from being closed.
If there are no signals connected to onClosing or none of them set the abort parameter then the onClose event is triggered. After this event the window will be "destroyed" (i.e. removed from the parent with parentGroup->remove(childWindow)).

Instead of toggling the visibility you could just call group->add(childWindow) again when you need to show the window again.

Alternatively, you can prevent the window from being closed in the onClosing event and change the visibility there:
childWindow->onClosing([=](bool* abort){
    *abort = true;


very precise as usual.