Added connect function to bind multiple signals at once

0.8
Bruno Van de Velde 2017-08-18 00:12:27 +02:00
parent a5784fb254
commit 42516dba8a
1 changed files with 21 additions and 1 deletions

View File

@ -582,7 +582,7 @@ namespace tgui
/// @brief Connects a signal handler that will be called when this signal is emitted
///
/// @param signalName Name of the signal
/// @param handler Callback function that is giventhe extra arguments provided to this function as arguments
/// @param handler Callback function that is given the extra arguments provided to this function as arguments
/// @param args Optional extra arguments to pass to the signal handler when the signal is emitted
///
/// @return Unique id of the connection
@ -615,6 +615,26 @@ namespace tgui
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Connect a signal handler to multiple signals
///
/// @param signalNames List of signal names that will trigger the signal handler
/// @param handler Callback function
/// @param args Optional extra arguments to pass to the signal handler when the signal is emitted
///
/// @return Unique id of the last connection. When passing e.g. 2 signal names, the first signal will correspond to id-1.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename Func, typename... Args>
unsigned int connect(std::initializer_list<std::string> signalNames, Func&& handler, const Args&... args)
{
unsigned int lastId = 0;
for (const auto& signalName : signalNames)
lastId = connect(signalName, handler, args...);
return lastId;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Disconnects a signal handler
///