Folowing code works great:
Just added
To child window
And
Inside while (gui.pollCallback(callback)) where all callbacks are checked.
I posted this "solution" in case somebody gets same problems as i did. If not nedded, feel free to delete entire topic (:
Code Select
#include <TGUI/TGUI.hpp>
void loadWidgets( tgui::Gui& gui )
{
tgui::ChildWindow::Ptr child(gui, "childWindow");
// child->load("../../widgets/Black.conf");
// child->setIcon("../icon.jpg");
child->load("Black.conf");
child->setSize(400, 400);
child->setBackgroundColor(sf::Color(80, 80, 80));
child->setPosition(200, 100);
child->setTitle("Child window");
child->hide();
child->bindCallback(tgui::ChildWindow::Closed);
child->setCallbackId(2);
tgui::Button::Ptr showChildWindow(gui);
showChildWindow->load("Black.conf");
showChildWindow->setSize(120, 40);
showChildWindow->setPosition(100, 100);
showChildWindow->setText("Show child window");
showChildWindow->bindCallback(tgui::Button::LeftMouseClicked);
showChildWindow->setCallbackId(1);
}
int main()
{
// Create the main window
sf::RenderWindow app(sf::VideoMode(800, 600), "Child window test");
tgui::Gui gui(app);
// gui.setGlobalFont("../../fonts/DejaVuSans.ttf");
gui.setGlobalFont("DejaVuSans.ttf");
loadWidgets(gui);
// Start the game loop
while (app.isOpen())
{
// Process events
sf::Event event;
while (app.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
app.close();
// Pass the event to all the widgets
gui.handleEvent(event);
}
tgui::Callback callback;
while (gui.pollCallback(callback))
{
if (callback.id == 1)
{
tgui::ChildWindow::Ptr Child = gui.get("childWindow");
Child->show();
}
if ( callback.id == 2 )
{
tgui::ChildWindow::Ptr Child = gui.get("childWindow");
Child->hide();
}
}
// Clear screen
app.clear();
// Draw the sprite
gui.draw();
// Update the window
app.display();
}
return EXIT_SUCCESS;
}
Just added
Code Select
child->bindCallback(tgui::ChildWindow::Closed);
child->setCallbackId(2);
To child window
And
Code Select
if ( callback.id == 2 )
{
tgui::ChildWindow::Ptr Child = gui.get("childWindow");
Child->hide();
}
Inside while (gui.pollCallback(callback)) where all callbacks are checked.
I posted this "solution" in case somebody gets same problems as i did. If not nedded, feel free to delete entire topic (: