I'm trying to bind a return key callback to an EditBox but have a bit of a problem: the callback is activated when the EditBox is clicked on. Whenever the return key is pressed when the EditBox is focused, the callback works as intended. Basically, two events (clicking on the EditBox and pressing Return in the EditBox) trigger the same callback. I stripped down my code to the absolute basic and the problem still occurs, leading me to believe either I am binding the callback incorrectly or there is a bug in TGUI.
I am using the TGUI code posted in the May 10 blog post.
Here's my basic, reproducible code.
I am using the TGUI code posted in the May 10 blog post.
Here's my basic, reproducible code.
Code Select
#include <iostream>
#include <SFML/Graphics.hpp>
#include <TGUI/TGUI.hpp>
// Declare global variables
sf::RenderWindow appWindow;
tgui::Window guiWindow(appWindow);
int main()
{
appWindow.create( sf::VideoMode( 1024, 768, 32 ), "Test" );
guiWindow.setGlobalFont( "resources/DejaVuSans.ttf" );
tgui::EditBox::Ptr editBox(guiWindow);
editBox->load("resources/objects/Black.conf");
editBox->setPosition(40, 200);
editBox->setSize(300, 30);
editBox->setCallbackId(1);
editBox->bindCallback( tgui::EditBox::EditBoxCallbacks::ReturnKeyPressed );
while (appWindow.isOpen())
{
sf::Event event;
while (appWindow.pollEvent(event))
{
if (event.type == sf::Event::Closed)
appWindow.close();
guiWindow.handleEvent(event);
}
tgui::Callback callback;
while (guiWindow.pollCallback(callback))
{
if (callback.id == 1)
std::cout << "Return pressed\n";
}
appWindow.clear();
guiWindow.drawGUI();
appWindow.display();
}
return 0;
}