From 0f8f98b9005803ab154b43dcad0db1f292072a4d Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Mon, 17 Nov 2025 12:54:55 +0800 Subject: Refactor window host. --- include/cru/ui/events/RoutedEvent.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'include/cru/ui/events/RoutedEvent.h') 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 class CRU_UI_API RoutedEvent { + friend controls::Window; + public: static_assert(std::is_base_of_v, "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* Direct() { return &direct_; } IEvent* Bubble() { return &bubble_; } IEvent* Tunnel() { return &tunnel_; } private: + std::string name_; + Event direct_; Event bubble_; Event tunnel_; }; -} // namespace cru::ui::event + +#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 -- cgit v1.2.3