TGUI & SFML - "pressed" event
« on: 31 July 2017, 09:59:34 »
Hi guys,

I've been using TGUI and SFML since few months on a little game quizz I developped.

There's an issue I am not able to solve regarding the "pressed" event.

When the game starts, a first window appears where the user needs to input its username and click OK. Then the quizz starts. However, when I run the code, if the user clicks OK, nothing happens. I figured out that the user has to click AND to move the mouse so that the event is correctly triggered.

Here is the code responsible for creating the OK button and the associated connect function (please let me know if providing other extracts of the code would help better):

// Create the "Ok" button
tgui::Button::Ptr button = theme->load("Button");
button->setSize(windowWidth / 2, windowHeight / 6);
button->setPosition(windowWidth / 4, windowHeight * 7 / 10);
button->setText("Ok");
gui.add(button);

// Call the login function when the button is pressed
button->connect("pressed", login, editBoxUsername);

Any help on this one?   :-\

*

texus

  • *****
  • 1163
    • View Profile
    • Texus's Blog
Re: TGUI & SFML - "pressed" event
« Reply #1 on: 31 July 2017, 10:15:56 »
That code should work fine. I would expect the error to be in the code where you handle your events: when gui.handleEvent is called with the mouse click release event as argument, the button will emit the pressed signal. Are you calling gui.handleEvent for each sfml event or is it possible that you are somehow buffering the events somewhere and only pass the previous sfml event when the next one arrived?
If you can't figure out where the issue comes from, you should write some minimal code that reproduces the problem so that I can test it myself.
« Last Edit: 31 July 2017, 10:35:59 by texus »