diff options
Diffstat (limited to 'include/cru/ui/events/RoutedEvent.h')
| -rw-r--r-- | include/cru/ui/events/RoutedEvent.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/include/cru/ui/events/RoutedEvent.h b/include/cru/ui/events/RoutedEvent.h index aa3331a6..58e50d63 100644 --- a/include/cru/ui/events/RoutedEvent.h +++ b/include/cru/ui/events/RoutedEvent.h @@ -8,6 +8,8 @@ namespace cru::ui::events { // EventArgs must be reference because the IsHandled property must be settable. template <typename TEventArgs> class CRU_UI_API RoutedEvent { + friend controls::Window; + public: static_assert(std::is_base_of_v<UiEventArgs, TEventArgs>, "TEventArgs must be subclass of UiEventArgs."); @@ -16,13 +18,29 @@ class CRU_UI_API RoutedEvent { using EventArgs = TEventArgs&; + explicit RoutedEvent(std::string name) : name_(std::move(name)) {} + + std::string GetName() const { return name_; } + IEvent<TEventArgs&>* Direct() { return &direct_; } IEvent<TEventArgs&>* Bubble() { return &bubble_; } IEvent<TEventArgs&>* Tunnel() { return &tunnel_; } private: + std::string name_; + Event<TEventArgs&> direct_; Event<TEventArgs&> bubble_; Event<TEventArgs&> tunnel_; }; -} // namespace cru::ui::event + +#define CRU_DEFINE_ROUTED_EVENT(name, arg_type) \ + private: \ + ::cru::ui::events::RoutedEvent<arg_type> name##Event_{#name}; \ + \ + public: \ + ::cru::ui::events::RoutedEvent<arg_type>* name##Event() { \ + return &name##Event_; \ + } + +} // namespace cru::ui::events |
