Adding signals to derived widgets

  • 2 Replies
  • 198 Views
Adding signals to derived widgets
« on: 28 December 2019, 13:08:52 »
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:
myGroupWidget.connect("GropWidgetPressed", [](){});
 
« Last Edit: 28 December 2019, 13:11:23 by Maksat »

*

texus

  • *****
  • 1551
    • View Profile
    • Texus's Blog
Re: Adding signals to derived widgets
« Reply #1 on: 28 December 2019, 13:18:48 »
Add the following to your derived class.
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:
onGropWidgetPress.emit(this);

Re: Adding signals to derived widgets
« Reply #2 on: 28 December 2019, 15:37:14 »
It worked! Thanks!