TGUI Forum

General Category => Help requests => Topic started by: starkhorn on 14 June 2015, 06:55:32

Title: Way to detect if the close button in a child window has been pressed
Post by: starkhorn on 14 June 2015, 06:55:32
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.
Title: Re: Way to detect if the close button in a child window has been pressed
Post by: texus on 14 June 2015, 11:39:31
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);
Title: Re: Way to detect if the close button in a child window has been pressed
Post by: starkhorn on 24 June 2015, 10:03:05
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.
Title: Re: Way to detect if the close button in a child window has been pressed
Post by: texus on 24 June 2015, 11:41:46
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.
Title: Re: Way to detect if the close button in a child window has been pressed
Post by: starkhorn on 24 June 2015, 12:07:59
ahhh - ok I see. Thank you yet again.