Adding signals to derived widgets

Started by Maksat, 28 December 2019, 13:08:52

Maksat

Hello! I made class inherited from tgui::Group, which contains some other widgets. Is it possible to add new signal like "GropWidgetPressed" so I could use it like this:
Code (cpp) Select

myGroupWidget.connect("GropWidgetPressed", [](){});

texus

Add the following to your derived class.
Code (cpp) Select
Signal onGropWidgetPress = {"GropWidgetPressed"};

Signal& getSignal(std::string signalName) override
{
    if (signalName == onGropWidgetPress.getName().toLower())
        return onGropWidgetPress;
    else
        return Group::getSignal(std::move(signalName));
}


In your code where you want the callback function to be called you call the emit function:
Code (cpp) Select
onGropWidgetPress.emit(this);

Maksat