Childwindow - Core Dumped when reopening
« on: 21 March 2014, 14:56:05 »
Here is simple code

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();

    tgui::Button::Ptr showChildWindow(gui);
   // showChildWindow->load("../../widgets/Black.conf");
    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()
{

    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);

    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();
                }
 
            }

        // Clear screen
        app.clear();

        // Draw the sprite
        gui.draw();

        // Update the window
        app.display();
    }


    return EXIT_SUCCESS;
}

What it does: Displays child window od given location. Problem is when clicking on  [X] on childwindow, it does close child window. But it doesnt hide it or anything, so i guess child window gets destroyed automaticly. After closing the child window, and clicking on same button to show child window i get core dumped. Which i guess its becouse child gets destroyed.

1. How to implement when clicking [X] button on child window, makes child window hide(), and not destroy()

2. I know i can add buttons to child window, and bindCallback to one button to serves as hide() for childwindow, but there still will be [X] displayed in child window titlebar when displaying child window, which i cant remove, and it is dangerous if somebody click on it.

« Last Edit: 21 March 2014, 14:58:55 by wmbuRn »

Re: Childwindow - Core Dumped when reopening
« Reply #1 on: 21 March 2014, 15:01:44 »
No delete button on topic. Forget this topic, i didnt see

enum tgui::ChildWindow::ChildWindowCallbacks

Defines specific triggers to ChildWindow.
Enumerator
LeftMousePressed    

The left mouse button was pressed (child window was thus brough to front)
Closed    

Child window was closed.
Moved    

Child window was moved.
AllChildWindowCallbacks    

All triggers defined in ChildWindow and its base classes.

in documentation. Sorry

Re: Childwindow - Core Dumped when reopening
« Reply #2 on: 21 March 2014, 15:10:40 »
Folowing code works great:
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 (: