aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/events/RoutedEvent.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-12-13 20:58:42 +0800
committercrupest <crupest@outlook.com>2021-12-13 20:58:42 +0800
commit21fccf43ec049569f690674840ca1a10420a40da (patch)
tree33341a51f41bc9d783221ad363e33ffeb177886b /include/cru/ui/events/RoutedEvent.hpp
parentc850d817cc0d8c2c80728f373f89dce91650023a (diff)
downloadcru-21fccf43ec049569f690674840ca1a10420a40da.tar.gz
cru-21fccf43ec049569f690674840ca1a10420a40da.tar.bz2
cru-21fccf43ec049569f690674840ca1a10420a40da.zip
...
Diffstat (limited to 'include/cru/ui/events/RoutedEvent.hpp')
-rw-r--r--include/cru/ui/events/RoutedEvent.hpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/cru/ui/events/RoutedEvent.hpp b/include/cru/ui/events/RoutedEvent.hpp
new file mode 100644
index 00000000..0cedc671
--- /dev/null
+++ b/include/cru/ui/events/RoutedEvent.hpp
@@ -0,0 +1,39 @@
+#pragma once
+#include "UiEventArgs.hpp"
+
+#include "cru/common/Event.hpp"
+
+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 <typename TEventArgs>
+class RoutedEvent {
+ public:
+ static_assert(std::is_base_of_v<UiEventArgs, TEventArgs>,
+ "TEventArgs must be subclass of UiEventArgs.");
+ static_assert(!std::is_reference_v<TEventArgs>,
+ "TEventArgs must not be reference.");
+
+ using RawEventArgs = TEventArgs;
+ using IEventType = IEvent<TEventArgs&>;
+ using EventArgs = typename IEventType::EventArgs;
+
+ RoutedEvent() = default;
+ RoutedEvent(const RoutedEvent& other) = delete;
+ RoutedEvent(RoutedEvent&& other) = delete;
+ RoutedEvent& operator=(const RoutedEvent& other) = delete;
+ RoutedEvent& operator=(RoutedEvent&& other) = delete;
+ ~RoutedEvent() = default;
+
+ IEvent<TEventArgs&>* Direct() { return &direct_; }
+
+ IEvent<TEventArgs&>* Bubble() { return &bubble_; }
+
+ IEvent<TEventArgs&>* Tunnel() { return &tunnel_; }
+
+ private:
+ Event<TEventArgs&> direct_;
+ Event<TEventArgs&> bubble_;
+ Event<TEventArgs&> tunnel_;
+};
+} // namespace cru::ui::event