Button problems

Started by Menko, 03 March 2018, 05:54:55

Menko

Hello,
I'm trying to get tgui working in my project and after trying a lot of things, nothing appears to be drawn,
and im not sure what is the problem. I'm using the latest dev version compiled from source (0.8-dev).

basicly, what i did is, in the header file

tgui::Gui gui;
tgui::Button::Ptr m_buttonQuit;
tgui::Theme m_theme;

And in the cpp file
Init() function

try
{
gui.setTarget(game->getWindow()); // getWindow returns the sf::RenderWindow
m_theme.load("Themes/Black.txt");
m_buttonQuit = tgui::Button::create();
m_buttonQuit->setRenderer(m_theme.getRenderer("Button"));
m_buttonQuit->setText("Quit");
m_buttonQuit->setPosition((game->getWindow().getSize().x / 2), ((game->getWindow().getSize().y / 2) + 100));
m_buttonQuit->setSize(20, 20);
m_buttonQuit->connect("pressed", [&]() { game->Quit(); });
gui.add(m_buttonQuit);
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
}

The handleInput() function:

sf::Event event;
while (game->getWindow().pollEvent(event))
{ a lot of stuff here
gui.handleEvent(event);
}

and lastly the Draw() function

game->getWindow().display();
gui.draw();

But window is just empty.
Thanks!


texus

You should call gui.draw() before calling display() on the sfml window, otherwise you are rendering to the next frame which will overdrawn by the next window.clear() call.