#pragma once #include "UiEventArgs.h" #include namespace cru::ui::events { // TEventArgs must not be a reference type. This class help add reference. // EventArgs must be reference because the IsHandled property must be settable. template class CRU_UI_API RoutedEvent { friend controls::ControlHost; public: static_assert(std::is_base_of_v, "TEventArgs must be subclass of UiEventArgs."); static_assert(!std::is_reference_v, "TEventArgs must not be reference."); using EventArgs = TEventArgs&; explicit RoutedEvent(std::string name) : name_(std::move(name)) {} std::string GetName() const { return name_; } IEvent* Direct() { return &direct_; } IEvent* Bubble() { return &bubble_; } IEvent* Tunnel() { return &tunnel_; } private: std::string name_; Event direct_; Event bubble_; Event tunnel_; }; #define CRU_DEFINE_ROUTED_EVENT(name, arg_type) \ private: \ ::cru::ui::events::RoutedEvent name##Event_{#name}; \ \ public: \ ::cru::ui::events::RoutedEvent* name##Event() { \ return &name##Event_; \ } } // namespace cru::ui::events