aboutsummaryrefslogtreecommitdiff
path: root/src/ui/window.hpp
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2018-11-28 19:32:58 +0800
committerGitHub <noreply@github.com>2018-11-28 19:32:58 +0800
commitdd75868a05cfc9d71b26f1197022c03ba481fe33 (patch)
tree6f50579da8be5b6be8792b0d832b76ba822c2760 /src/ui/window.hpp
parentee22597122612cd75fe62f5d808cb51478373fad (diff)
parentd98e9ef82be277190c883e4ee7547516dbd620b6 (diff)
downloadcru-dd75868a05cfc9d71b26f1197022c03ba481fe33.tar.gz
cru-dd75868a05cfc9d71b26f1197022c03ba481fe33.tar.bz2
cru-dd75868a05cfc9d71b26f1197022c03ba481fe33.zip
Merge pull request #30 from crupest/routed-event
Develop routed events.
Diffstat (limited to 'src/ui/window.hpp')
-rw-r--r--src/ui/window.hpp33
1 files changed, 5 insertions, 28 deletions
diff --git a/src/ui/window.hpp b/src/ui/window.hpp
index e82aa585..d7301eb5 100644
--- a/src/ui/window.hpp
+++ b/src/ui/window.hpp
@@ -4,6 +4,7 @@
#include "pre.hpp"
#include "system_headers.hpp"
+#include <list>
#include <map>
#include <memory>
@@ -241,10 +242,10 @@ namespace cru::ui
public:
//*************** region: events ***************
- events::UiEvent activated_event;
- events::UiEvent deactivated_event;
-
- events::WindowNativeMessageEvent native_message_event;
+ Event<events::UiEventArgs> activated_event;
+ Event<events::UiEventArgs> deactivated_event;
+
+ Event<events::WindowNativeMessageEventArgs> native_message_event;
private:
//*************** region: native operations ***************
@@ -281,30 +282,6 @@ namespace cru::ui
//*************** region: event dispatcher helper ***************
- template<typename EventArgs>
- using EventMethod = void (Control::*)(EventArgs&);
-
- // Dispatch the event.
- //
- // This will invoke the "event_method" of the control and its parent and parent's
- // parent ... (until "last_receiver" if it's not nullptr) with appropriate args.
- //
- // Args is of type "EventArgs". The first init argument is "sender", which is
- // automatically bound to each receiving control. The second init argument is
- // "original_sender", which is unchanged. And "args" will be perfectly forwarded
- // as the rest arguments.
- template<typename EventArgs, typename... Args>
- void DispatchEvent(Control* original_sender, EventMethod<EventArgs> event_method, Control* last_receiver, Args&&... args)
- {
- auto control = original_sender;
- while (control != nullptr && control != last_receiver)
- {
- EventArgs event_args(control, original_sender, std::forward<Args>(args)...);
- (control->*event_method)(event_args);
- control = control->GetParent();
- }
- }
-
void DispatchMouseHoverControlChangeEvent(Control* old_control, Control * new_control, const Point& point);
private: