How can i use the sliders callback functions?

Started by Theodor, 15 August 2018, 12:56:49

Theodor

Hello, I want to start working with this awesome library but I don't know how to use the callback function. For example, what is the event name for when the slider updates like for the button it is "pressed"

This is the current code I have for my slider:

        auto slider = tgui::Slider::create()
   slider->setRenderer(theme.getRenderer("Slider"));
   slider->setPosition(10, 560);
   slider->setSize(200, 18);
   slider->setValue(4);
   slider->connect("OnValueChange", [&]() {std::cout << "Slider value: " << gui.get<tgui::Slider>("Slider")->getValue() << std::endl; } );
   gui.add(slider,"Slider");

But when I run it I get an exception like "the signal OnValueChange does not exist" so I wonder what is the event name called and how can I see all the events name for all the widgets?

I found the solution and it is "ValueChanged" but I found it when I looked through the source code and I'm sure there is a much better way.

texus

I already told myself multiple times that I should make a list of event names, but I never find the time and motivation to do it. For now you can find them in the documentation under the "Public Attributes" (e.g. https://tgui.eu/documentation/0.8/classtgui_1_1Slider.html#pub-attribs for Slider).
You will find a line like this:
SignalFloat onValueChange = {"ValueChanged"}

Ignore the "onValueChange", I intend to deprecate accessing the variable in the future. The name of the signal is the one between quotes, "ValueChanged" in this case. The SignalFloat also shows that the function can take an optional float as parameter, but the exact parameters may not always be that easy to guess from the signal name. Hopefully the one line description ("Value of the slider changed. Optional parameter: new value." here) will be enough in these cases.