aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/event/ui_event.hpp
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-08-11 17:31:20 +0800
committer杨宇千 <crupest@outlook.com>2019-08-11 17:31:20 +0800
commit3a8abe0aed9bb72ed64cbfe9f2f83a0db285e14c (patch)
tree67b1ab631ec78c3bf84d009c038a9c83632adee6 /include/cru/ui/event/ui_event.hpp
parent0e35b2c022599bca2df61488945f07e4d6b4eb35 (diff)
downloadcru-3a8abe0aed9bb72ed64cbfe9f2f83a0db285e14c.tar.gz
cru-3a8abe0aed9bb72ed64cbfe9f2f83a0db285e14c.tar.bz2
cru-3a8abe0aed9bb72ed64cbfe9f2f83a0db285e14c.zip
...
Diffstat (limited to 'include/cru/ui/event/ui_event.hpp')
-rw-r--r--include/cru/ui/event/ui_event.hpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/include/cru/ui/event/ui_event.hpp b/include/cru/ui/event/ui_event.hpp
index f36e40a2..b962ff76 100644
--- a/include/cru/ui/event/ui_event.hpp
+++ b/include/cru/ui/event/ui_event.hpp
@@ -6,6 +6,7 @@
#include <memory>
#include <optional>
+#include <type_traits>
namespace cru::platform::graph {
class Painter;
@@ -45,22 +46,28 @@ 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 EventArgs = TEventArgs;
- RoutedEvent()
- : direct(new Event<TEventArgs&>()),
- bubble(new Event<TEventArgs&>()),
- tunnel(new Event<TEventArgs&>()) {}
+ RoutedEvent() = default;
RoutedEvent(const RoutedEvent& other) = delete;
RoutedEvent(RoutedEvent&& other) = delete;
RoutedEvent& operator=(const RoutedEvent& other) = delete;
RoutedEvent& operator=(RoutedEvent&& other) = delete;
~RoutedEvent() = default;
- const std::unique_ptr<IEvent<TEventArgs&>> direct;
- const std::unique_ptr<IEvent<TEventArgs&>> bubble;
- const std::unique_ptr<IEvent<TEventArgs&>> tunnel;
+ 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_;
};
class MouseEventArgs : public UiEventArgs {