ChildWindow Questions
« on: 22 December 2017, 16:10:43 »
Hello, i have few questions about the ChildWindow Widget.

1. How can i check if my ChildWindow has been exited?
2. When the ChildWindow has been exited, can i reopen it ?
3. When i exit the ChildWindow is he destroying automatically ?
4. Can i hide the Exit button ?
5. When ChildWindow is being destroyed all the other Ptr's inside the widget are being Deleted aswell ?
« Last Edit: 22 December 2017, 16:15:56 by therealcain »

*

texus

  • *****
  • 1236
    • View Profile
    • Texus's Blog
Re: ChildWindow Questions
« Reply #1 on: 22 December 2017, 18:45:58 »
1) The ChildWindow sends a "Closed" signal. You can just connect to it like this:
childWindow->connect("closed", []{ std::cout << "Window closed" << std::endl; });

If you connect to the Closed event then you are responsible for removing the child window yourself. The above code will just print "Window closed" but the window will remain open. This was done to allow you to cancel a close (e.g. ask user to save before closing). If no signal is bound, the window is removed automatically, but if you connect to the Closes event then you need something like this:
childWindow->connect("closed", [](tgui::ChildWindow::Ptr c){ /*some code*/;  c->destroy(); });

The "c->destroy();" is equivalent to
if (c->getParent())
    c->getParent()->remove(c);

3 and 5) All widgets are shared pointers, which means they are destroyed when neither you nor the gui still has a pointer to it. If you close the child window and no signal is connected like shown above, the child window will be removed from its parent. If you don't keep a pointer to the child window or one of the widgets inside it then they will be destroyed at that moment.

2) If a window is closed, it gets removed from its parent by default as already mentioned above. If you still had a pointer to the child window in your own code then you simply have to add it again. If you didn't keep a pointer then you will have to recreate the child window completely.

An alternative could be to connect to the Close signal and just call "c->hide()", in which case it is still part of the gui and you just have to call show() on it later to "open" the window again.

4) You can use the setTitleButtons function for this:
childWindow->setTitleButtons(tgui::ChildWindow::TitleButton::None);

Re: ChildWindow Questions
« Reply #2 on: 22 December 2017, 20:13:40 »
1) The ChildWindow sends a "Closed" signal. You can just connect to it like this:
childWindow->connect("closed", []{ std::cout << "Window closed" << std::endl; });

If you connect to the Closed event then you are responsible for removing the child window yourself. The above code will just print "Window closed" but the window will remain open. This was done to allow you to cancel a close (e.g. ask user to save before closing). If no signal is bound, the window is removed automatically, but if you connect to the Closes event then you need something like this:
childWindow->connect("closed", [](tgui::ChildWindow::Ptr c){ /*some code*/;  c->destroy(); });

The "c->destroy();" is equivalent to
if (c->getParent())
    c->getParent()->remove(c);

3 and 5) All widgets are shared pointers, which means they are destroyed when neither you nor the gui still has a pointer to it. If you close the child window and no signal is connected like shown above, the child window will be removed from its parent. If you don't keep a pointer to the child window or one of the widgets inside it then they will be destroyed at that moment.

2) If a window is closed, it gets removed from its parent by default as already mentioned above. If you still had a pointer to the child window in your own code then you simply have to add it again. If you didn't keep a pointer then you will have to recreate the child window completely.

An alternative could be to connect to the Close signal and just call "c->hide()", in which case it is still part of the gui and you just have to call show() on it later to "open" the window again.

4) You can use the setTitleButtons function for this:
childWindow->setTitleButtons(tgui::ChildWindow::TitleButton::None);

thank you!
I just realized that most of the questions are kind of the same.