TGUI  0.10-beta

Signal to which the user can subscribe to get callbacks from. More...

#include <TGUI/Signal.hpp>

Inheritance diagram for tgui::Signal:
tgui::SignalTyped< FloatRect > tgui::SignalTyped< const String & > tgui::SignalTyped< bool * > tgui::SignalTyped< Vector2f > tgui::SignalTyped< Color > tgui::SignalTyped< const std::vector< Filesystem::Path > & > tgui::SignalTyped< float > tgui::SignalTyped< unsigned int > tgui::SignalTyped< int > tgui::SignalTyped< bool > tgui::SignalTyped2< float, float > tgui::SignalTyped2< int, bool * > tgui::SignalAnimationType tgui::SignalChildWindow tgui::SignalItem tgui::SignalItemHierarchy tgui::SignalShowEffect tgui::SignalTyped< T > tgui::SignalTyped2< T1, T2 >

Public Member Functions

virtual ~Signal ()=default
 Default destructor.
 
 Signal (String &&name, std::size_t extraParameters=0)
 Constructor. More...
 
 Signal (const Signal &other)
 Copy constructor which will not copy the signal handlers.
 
 Signal (Signal &&other) noexcept=default
 Default move constructor.
 
Signaloperator= (const Signal &other)
 Copy assignment operator which will not copy the signal handlers.
 
Signaloperator= (Signal &&other) noexcept=default
 Default move assignment operator.
 
template<typename Func , typename... BoundArgs>
unsigned int operator() (const Func &func, const BoundArgs &... args)
 Connects a signal handler that will be called when this signal is emitted. More...
 
template<typename Func , typename... BoundArgs, typename std::enable_if_t< std::is_convertible< Func, std::function< void(const BoundArgs &...)> >::value > * = nullptr>
unsigned int connect (const Func &func, const BoundArgs &... args)
 Connects a signal handler that will be called when this signal is emitted. More...
 
template<typename Func , typename... BoundArgs, typename std::enable_if_t< std::is_convertible< Func, std::function< void(const BoundArgs &..., std::shared_ptr< Widget >, const String &)> >::value , * = nullptr>
unsigned int connectEx (const Func &func, const BoundArgs &... args)
 Connects a signal handler that will be called when this signal is emitted. More...
 
bool disconnect (unsigned int id)
 Disconnect a signal handler from this signal. More...
 
void disconnectAll ()
 Disconnect all signal handler from this signal.
 
bool emit (const Widget *widget)
 Call all connected signal handlers. More...
 
String getName () const
 Returns the name given to the signal. More...
 
void setEnabled (bool enabled)
 Changes whether this signal calls the connected functions when triggered. More...
 
bool isEnabled () const
 Returns whether this signal calls the connected functions when triggered. More...
 

Static Protected Member Functions

static std::shared_ptr< WidgetgetWidget ()
 Extracts the widget stored in the first parameter.
 
template<typename Type >
static const std::decay_t< Type > & dereferenceParam (std::size_t paramIndex)
 Turns the void* parameters back into its original type right before calling the callback function.
 
template<typename Func , typename... Args, typename std::enable_if< std::is_member_pointer< typename std::decay< Func >::type >::value >::type * = nullptr>
static void invokeFunc (Func &&func, Args &&... args)
 
template<typename Func , typename... Args, typename std::enable_if<!std::is_member_pointer< typename std::decay< Func >::type >::value >::type * = nullptr>
static void invokeFunc (Func &&func, Args &&... args)
 

Protected Attributes

bool m_enabled = true
 
String m_name
 
std::unordered_map< unsigned int, std::function< void()> > m_handlers
 

Static Protected Attributes

static unsigned int m_lastSignalId
 
static std::deque< const void * > m_parameters
 

Detailed Description

Signal to which the user can subscribe to get callbacks from.

Constructor & Destructor Documentation

◆ Signal()

tgui::Signal::Signal ( String &&  name,
std::size_t  extraParameters = 0 
)
inline

Constructor.

Parameters
nameName of the signal
extraParametersAmount of extra parameters to reserve space for

Member Function Documentation

◆ connect()

template<typename Func , typename... BoundArgs, typename std::enable_if_t< std::is_convertible< Func, std::function< void(const BoundArgs &...)> >::value > * = nullptr>
unsigned int tgui::Signal::connect ( const Func &  func,
const BoundArgs &...  args 
)
inline

Connects a signal handler that will be called when this signal is emitted.

Parameters
funcCallback function
argsAdditional arguments to pass to the function
Returns
Unique id of the connection

◆ connectEx()

template<typename Func , typename... BoundArgs, typename std::enable_if_t< std::is_convertible< Func, std::function< void(const BoundArgs &..., std::shared_ptr< Widget >, const String &)> >::value , * = nullptr>
unsigned int tgui::Signal::connectEx ( const Func &  func,
const BoundArgs &...  args 
)
inline

Connects a signal handler that will be called when this signal is emitted.

Parameters
funcCallback function that is given a pointer to the widget and the name of the signal as arguments
argsAdditional arguments to pass to the function
Returns
Unique id of the connection

◆ disconnect()

bool tgui::Signal::disconnect ( unsigned int  id)

Disconnect a signal handler from this signal.

Parameters
idUnique id of the connection returned by the connect function
Returns
True when a connection with this id existed and was removed

◆ emit()

bool tgui::Signal::emit ( const Widget widget)

Call all connected signal handlers.

Parameters
widgetThe sender of the signal
Returns
True when at least one signal handler was called

◆ getName()

String tgui::Signal::getName ( ) const
inline

Returns the name given to the signal.

Returns
signal name

◆ isEnabled()

bool tgui::Signal::isEnabled ( ) const
inline

Returns whether this signal calls the connected functions when triggered.

Returns
Is the signal enabled?

Signals are enabled by default. Temporarily disabling the signal is the better alternative to disconnecting the handler and connecting it again a few lines later.

◆ operator()()

template<typename Func , typename... BoundArgs>
unsigned int tgui::Signal::operator() ( const Func &  func,
const BoundArgs &...  args 
)
inline

Connects a signal handler that will be called when this signal is emitted.

Parameters
funcCallback function that can be passed to the connect function
argsAdditional arguments to pass to the function
Returns
Unique id of the connection

◆ setEnabled()

void tgui::Signal::setEnabled ( bool  enabled)
inline

Changes whether this signal calls the connected functions when triggered.

Parameters
enabledIs the signal enabled?

Signals are enabled by default. Temporarily disabling the signal is the better alternative to disconnecting the handler and connecting it again a few lines later.


The documentation for this class was generated from the following file: