Way to detect if the close button in a child window has been pressed

Started by starkhorn, 14 June 2015, 06:55:32

starkhorn

I'm looking for a way to see if the close button in a child window title bar has been pressed. Is there a hard-coded callback ID for example? Basically as well as just closing the child window, I also want to trigger other events as well.

texus

It has a Closed trigger which you can bind.
Code (cpp) Select
childWindow->bindCallback(tgui::ChildWindow::Closed);

If the Closed trigger is not bound, then clicking the close button will close the window. However, once you bind the close button you will get the ability to keep it open, so you will have to close it yourself. Either childWindow->destroy() or parent.remove(widget) will do that. The callback class contains a "widget" pointer which can be used for the remove.
Code (cpp) Select
gui.remove(callback.widget);

starkhorn

Hi Texus,

I'm really confused on this one. So I set the callback as above ,i.e.

Code (cpp) Select

childWindow->bindCallback(tgui::ChildWindow::Closed);


Then in the gui.pollCallback loop, I'm checking if this callback id is hit, i.e.

Code (cpp) Select

if (callback.id == tgui::ChildWindow::Closed)
{
int test = 0;
}


However this doesn't get triggered - so I'm a bit confused here as to why I'm unable to detect when the closed child window is pressed.

texus

callback.id contains the number that you can change with childWindow->setCallbackId. What you need is callback.trigger which will equal the tgui::ChildWindow::Closed.

starkhorn