ChildWindow close

  • 2 Replies
  • 93 Views
ChildWindow close
« on: 01 October 2021, 12:06:05 »
Hello,

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?

Thanks

Stefano

*

texus

  • *****
  • 1626
    • View Profile
    • Texus's Blog
Re: ChildWindow close
« Reply #1 on: 01 October 2021, 12:46:17 »
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:
Code: [Select]
childWindow->onClosing([=](bool* abort){
    *abort = true;
    childWindow->setVisible(false);
});

Re: ChildWindow close
« Reply #2 on: 01 October 2021, 13:49:27 »
Thanks,
very precise as usual.