26#ifndef TGUI_SIGNAL_MANAGER_HPP
27#define TGUI_SIGNAL_MANAGER_HPP
30#include <TGUI/Widget.hpp>
44 typedef std::shared_ptr<SignalManager>
Ptr;
45 typedef std::shared_ptr<const SignalManager>
ConstPtr;
47 using Delegate = std::function<void()>;
48 using DelegateEx = std::function<void(std::shared_ptr<Widget>,
const String&)>;
50 typedef std::weak_ptr<Widget> Weak;
51 typedef unsigned int SignalID;
57 std::pair<Delegate, DelegateEx> func;
64 unsigned int signalWidgetID;
91#if defined(__cpp_if_constexpr) && (__cpp_if_constexpr >= 201606L)
102 template <
typename Func,
typename... BoundArgs>
103 unsigned int connect(
String widgetName,
String signalName, Func&& handler,
const BoundArgs&... args);
116 template <
typename Func,
typename... Args,
typename std::enable_if<std::is_convertible<Func, std::function<void(
const Args&...)>>::value>::type* =
nullptr>
117 unsigned int connect(
String widgetName,
String signalName, Func&& handler,
const Args&... args);
131 template <
typename Func,
typename... BoundArgs,
typename std::enable_if<!std::is_convertible<Func, std::function<void(
const BoundArgs&...)>>::value
132 && std::is_convertible<Func, std::function<void(
const BoundArgs&..., std::shared_ptr<Widget>,
const String&)>>::value>::type* =
nullptr>
133 unsigned int connect(
String widgetName,
String signalName, Func&& handler, BoundArgs&&... args);
161 virtual void remove(
Widget* widget);
168 unsigned int generateUniqueId();
170 unsigned int m_lastId;
179 std::pair<Delegate, DelegateEx> makeSignal(
const Delegate&);
185 std::pair<Delegate, DelegateEx> makeSignalEx(
const DelegateEx&);
202 std::vector<Weak> m_widgets;
203 std::map<SignalID, SignalTuple> m_signals;
204 std::vector<ConnectedSignalTuple> m_connectedSignals;
209#if defined(__cpp_if_constexpr) && (__cpp_if_constexpr >= 201606L)
210 template <
typename Func,
typename... BoundArgs>
213 const unsigned int id = generateUniqueId();
215 if constexpr (std::is_convertible_v<Func, std::function<void(
const BoundArgs&...)>>
216 && std::is_invocable_v<
decltype(&handler), BoundArgs...>
217 && !std::is_function_v<Func>)
220 m_signals[id] = {widgetName, signalName, makeSignal([=, f=std::function<
void(
const BoundArgs&...)>(handler)]{ std::invoke(f, args...); })};
222 else if constexpr (std::is_convertible_v<Func, std::function<void(
const BoundArgs&...)>>)
225 m_signals[id] = {widgetName, signalName, makeSignal([=]{ std::invoke(handler, args...); })};
227 else if constexpr (std::is_convertible_v<Func, std::function<void(
const BoundArgs&...,
const std::shared_ptr<Widget>&,
const String&)>>
228 && std::is_invocable_v<
decltype(&handler), BoundArgs...,
const std::shared_ptr<Widget>&,
const String&>
229 && !std::is_function_v<Func>)
232 m_signals[id] = {widgetName, signalName, makeSignalEx([=, f=std::function<
void(
const BoundArgs&...,
const std::shared_ptr<Widget>& w,
const String& s)>(handler)](
const std::shared_ptr<Widget>& w,
const String& s){ std::invoke(f, args..., w, s); })};
237 m_signals[id] = {widgetName, signalName, makeSignalEx([=](
const std::shared_ptr<Widget>& w,
const String& s){ std::invoke(handler, args..., w, s); })};
244 template <
typename Func,
typename... Args,
typename std::enable_if<std::is_convertible<Func, std::function<void(
const Args&...)>>::value>::type*>
247 const unsigned int id = generateUniqueId();
248 m_signals[id] = {widgetName, signalName, makeSignal([f=std::function<
void(
const Args&...)>(handler),args...](){ f(args...); })};
254 template <
typename Func,
typename... BoundArgs,
typename std::enable_if<!std::is_convertible<Func, std::function<void(
const BoundArgs&...)>>::value
255 && std::is_convertible<Func, std::function<void(
const BoundArgs&..., std::shared_ptr<Widget>,
const String&)>>::value>::type*>
258 const unsigned int id = generateUniqueId();
259 m_signals[id] = {widgetName, signalName, makeSignalEx(
260 [f=std::function<
void(
const BoundArgs&...,
const std::shared_ptr<Widget>&,
const String&)>(handler), args...]
261 (
const std::shared_ptr<Widget>& w,
const String& s)
262 { f(args..., w, s); }
Definition SignalManager.hpp:41
virtual void connect(SignalID id)
Function that is called each time new signal is created with it id.
std::shared_ptr< const SignalManager > ConstPtr
Shared constant widget pointer.
Definition SignalManager.hpp:45
virtual bool disconnect(unsigned int id)
Disconnect a signal handler.
virtual void disconnectAll()
Disconnect all signal handler.
unsigned int connect(String widgetName, String signalName, Func &&handler, const Args &... args)
Connects a signal handler that will be called when this signal is emitted.
Definition SignalManager.hpp:245
virtual ~SignalManager()
Destructor.
SignalManager()
Default constructor.
std::shared_ptr< SignalManager > Ptr
Shared widget pointer.
Definition SignalManager.hpp:44
static SignalManager::Ptr getSignalManager()
Retrieves Signal Manager that will be used to operate a signal.
static void setDefaultSignalManager(const SignalManager::Ptr &manager)
Sets Signal Manager that will be used to operate a signal.
Wrapper class to store strings.
Definition String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
Definition SignalManager.hpp:61
Definition SignalManager.hpp:54