I have to retrieve some information from ChildWindow when it closing, but without calling destroy/0 the window doesn't disappear.
Here is MCVE:
#include <TGUI/TGUI.hpp>
#include <iostream>
class MyFrame
{
public:
MyFrame()
{
window.create(sf::VideoMode(800, 600), "TGUI window");
gui.setTarget(window);
panel = tgui::Panel::create();
auto b = tgui::Button::create();
b->setText("Click");
b->connect("pressed", [this]()
{
auto ptr = tgui::ChildWindow::create("Test");
ptr->connect("Closed", [this, ptr]()
{
std::cout << ptr->getTitle().toAnsiString() << '\n';
//ptr->destroy(); // all works if uncomment
});
panel->add(ptr);
});
panel->add(b);
gui.add(panel);
}
void main()
{
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
gui.handleEvent(event);
}
window.clear();
gui.draw();
window.display();
}
}
private:
sf::RenderWindow window;
tgui::Gui gui;
tgui::Panel::Ptr panel;
};
int main()
{
MyFrame().main();
}
Is it correct behaviour or I am doing something wrong and there is the right way for such situation?