aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/events/RoutedEvent.h
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-11-17 12:54:55 +0800
committerYuqian Yang <crupest@crupest.life>2025-11-17 12:54:55 +0800
commit0f8f98b9005803ab154b43dcad0db1f292072a4d (patch)
tree0a43d5a9c4e3b747ad955fc30a143aa07ab5888d /include/cru/ui/events/RoutedEvent.h
parentb68f9f52a3ecdd8e379dd60ac1c1366e76695464 (diff)
downloadcru-0f8f98b9005803ab154b43dcad0db1f292072a4d.tar.gz
cru-0f8f98b9005803ab154b43dcad0db1f292072a4d.tar.bz2
cru-0f8f98b9005803ab154b43dcad0db1f292072a4d.zip
Refactor window host.
Diffstat (limited to 'include/cru/ui/events/RoutedEvent.h')
-rw-r--r--include/cru/ui/events/RoutedEvent.h20
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