v0.7 signals
« on: 04 September 2015, 22:28:37 »
Hi,

Ok so I tried v0.7 for the first time today. I put in my v0.69 code and had zillions of compile errors as alot has changed. :)

Most are pretty easy to understand/modify, i.e. there is the renderer class and also there is no load method but we need to use the theme->load etc

However one thing that I am confused about is the change to signals.

In v0.69 there was the below in order to know when a button had been pressed with the left mouse button.

    button->bindCallback(tgui::Button::LeftMouseClicked);
    button->setCallbackId(1);
 

Now in v0.70, I get a compile error that tgui::Button::LeftMouseClicked does not exist.

I see in the v0.7 example code that it uses the connect method.

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

Ok seems simple enough but what I do not get there is how does the button widget know that this function gets triggered when the left mouse button is clicked. what if I wanted to do something if the right mouse button is clicked or if the middle button etc ?

I am sure I am missing something obvious here but I just don't quite get it. :)

*

texus

  • *****
  • 1163
    • View Profile
    • Texus's Blog
Re: v0.7 signals
« Reply #1 on: 04 September 2015, 22:32:52 »
Quote
how does the button widget know that this function gets triggered when the left mouse button is clicked. what if I wanted to do something if the right mouse button is clicked or if the middle button etc ?
Middle or right mouse buttons were never supported (tgui doesn't even process these events at the moment). I basically just renamed LeftMouseClicked to Pressed. There is a small difference between the two because LeftMouseClicked only activated on click while Pressed is also triggered when the button is focused and you press space or return, but since focusing widgets is something that never really functioned well in tgui I guess you could say that it is just a renaming.

Re: v0.7 signals
« Reply #2 on: 04 September 2015, 22:59:18 »
Ok, so in the connect function, the signal "pressed" is actually not a user-definable signal. It is a signal that is part of the widget constructor,

i.e. in button.cpp I see the line below in the button constructor.


addSignal<sf::String>("Pressed");
 

For some reason I thought the first parameter of the connect function could be whatever we wanted, i.e. like the setCallbackId method.

Re-reading the class documentation of v0.7, I now see the signal section, so ok this makes more sense now.

https://tgui.eu/documentation/v0.7/classtgui_1_1Button.html

"Detailed Description

Button widget.

Signals:

    Pressed (the button was pressed)
        Optional parameter sf::String: Caption of the button
        Uses Callback member 'text'
    Inherited signals from ClickableWidget"

One question, what is difference between the button pressed and the clickableWidget clicked signal?

*

texus

  • *****
  • 1163
    • View Profile
    • Texus's Blog
Re: v0.7 signals
« Reply #3 on: 04 September 2015, 23:06:06 »
Quote
One question, what is difference between the button pressed and the clickableWidget clicked signal?
The "clicked" trigger is available for a lot of widgets, "pressed" is specific for button. There are two differences, I already mentioned the first one about the pressed signal being triggered when the button is focused and you press space. The second one is about the information you get in your callback: "clicked" gives you the position where you clicked while "pressed" gives you the text of the button. But if you just connect a function without parameters then you won't notice this difference.

Edit: but don't try to focus your button to test this difference, the focus function won't work with any of the themes that tgui ships with.
« Last Edit: 04 September 2015, 23:12:19 by texus »