gigawidgets 0.3.55
A wxWidgets-style UI library for the Arduino Giga Display Shield.
 
Loading...
Searching...
No Matches
event_handlers.hpp
Go to the documentation of this file.
1
2#pragma once
3#include <ctime>
4#include <functional>
5
6#include "event.hpp"
7
8#define _DERIVE_EVENT(T, FUNC_NAME) \
9 inline void FUNC_NAME(std::function<void(T &, const Event &)> callback) { \
10 Widget::FUNC_NAME([callback](Widget &widget, const Event &event) { callback(reinterpret_cast<T &>(widget), event); }); \
11 } \
12 inline void FUNC_NAME(std::function<void(T &)> callback) { \
13 Widget::FUNC_NAME([callback](Widget &widget, const Event &) { callback(reinterpret_cast<T &>(widget)); }); \
14 }
15
16#define _DERIVE_EVENT_TIME(T, FUNC_NAME) \
17 inline void FUNC_NAME(std::function<void(T &, const Event &, time_t)> callback) { \
18 Widget::FUNC_NAME([callback](Widget &widget, const Event &event, time_t time) { callback(reinterpret_cast<T &>(widget), event, time); }); \
19 } \
20 inline void FUNC_NAME(std::function<void(T &, const Event &)> callback) { \
21 Widget::FUNC_NAME([callback](Widget &widget, const Event &event, time_t) { callback(reinterpret_cast<T &>(widget), event); }); \
22 } \
23 inline void FUNC_NAME(std::function<void(T &, time_t)> callback) { \
24 Widget::FUNC_NAME([callback](Widget &widget, const Event &, time_t time) { callback(reinterpret_cast<T &>(widget), time); }); \
25 } \
26 inline void FUNC_NAME(std::function<void(T &)> callback) { \
27 Widget::FUNC_NAME([callback](Widget &widget, const Event &, time_t) { callback(reinterpret_cast<T &>(widget)); }); \
28 }
29
30#define DERIVE_EVENT_HANDLERS(T) \
31 using Widget::onpress; \
32 _DERIVE_EVENT(T, onpress) \
33 using Widget::onrelease; \
34 _DERIVE_EVENT(T, onrelease) \
35 using Widget::onblur; \
36 _DERIVE_EVENT(T, onblur) \
37 using Widget::onclick; \
38 _DERIVE_EVENT(T, onclick) \
39 using Widget::onhold; \
40 _DERIVE_EVENT_TIME(T, onhold)
41
42namespace ui {
43
48template <class T>
50public:
56 virtual void onpress(std::function<void(T &, const Event &)> callback) = 0;
57
63 virtual void onrelease(std::function<void(T &, const Event &)> callback) = 0;
64
70 virtual void onblur(std::function<void(T &, const Event &)> callback) = 0;
71
77 virtual void onhold(std::function<void(T &, const Event &, time_t)> callback) = 0;
78
87 inline void onclick(std::function<void(T &, const Event &)> callback) {
88 onrelease(callback);
89 }
90};
91
96template <class T>
98public:
104
110 inline void onpress(std::function<void(T &)> callback) {
111 onpress([callback](T &widget, const Event &) { callback(widget); });
112 }
113
119 inline void onpress(std::function<void(const Event &)> callback) {
120 onpress([callback](T &, const Event &event) { callback(event); });
121 }
122
128 inline void onpress(std::function<void()> callback) {
129 onpress([callback](T &, const Event &) { callback(); });
130 }
131
137 inline void onrelease(std::function<void(T &)> callback) {
138 onrelease([callback](T &widget, const Event &) { callback(widget); });
139 }
140
146 inline void onrelease(std::function<void(const Event &)> callback) {
147 onrelease([callback](T &, const Event &event) { callback(event); });
148 }
149
155 inline void onrelease(std::function<void()> callback) {
156 onrelease([callback](T &, const Event &) { callback(); });
157 }
158
164 inline void onblur(std::function<void(T &)> callback) {
165 onblur([callback](T &widget, const Event &) { callback(widget); });
166 }
167
173 inline void onblur(std::function<void(const Event &)> callback) {
174 onblur([callback](T &, const Event &event) { callback(event); });
175 }
176
182 inline void onblur(std::function<void()> callback) {
183 onblur([callback](T &, const Event &) { callback(); });
184 }
185
191 inline void onhold(std::function<void(T &, time_t)> callback) {
192 onhold([callback](T &widget, const Event &, time_t time) { callback(widget, time); });
193 }
194
200 inline void onhold(std::function<void(const Event &, time_t)> callback) {
201 onhold([callback](T &, const Event &event, time_t time) { callback(event, time); });
202 }
203
209 inline void onhold(std::function<void(time_t)> callback) {
210 onhold([callback](T &, const Event &, time_t time) { callback(time); });
211 }
212
218 inline void onhold(std::function<void(T &)> callback) {
219 onhold([callback](T &widget, const Event &, time_t) { callback(widget); });
220 }
221
227 inline void onhold(std::function<void(const Event &)> callback) {
228 onhold([callback](T &, const Event &event, time_t) { callback(event); });
229 }
230
236 inline void onhold(std::function<void()> callback) {
237 onhold([callback](T &, const Event &, time_t) { callback(); });
238 }
239
248 inline void onclick(std::function<void(T &)> callback) {
249 onclick([callback](T &widget, const Event &) { callback(widget); });
250 }
251
260 inline void onclick(std::function<void(const Event &)> callback) {
261 onclick([callback](T &, const Event &event) { callback(event); });
262 }
263
272 inline void onclick(std::function<void()> callback) {
273 onclick([callback](T &, const Event &) { callback(); });
274 }
275};
276
277} // namespace ui
Virtual function definitions for default event handler functions.
Definition event_handlers.hpp:49
void onclick(std::function< void(T &, const Event &)> callback)
Register a touchscreen event handler that triggers on release.
Definition event_handlers.hpp:87
virtual void onblur(std::function< void(T &, const Event &)> callback)=0
Register a touchscreen event handler that triggers when the widget stops being pressed.
virtual void onhold(std::function< void(T &, const Event &, time_t)> callback)=0
Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
virtual void onpress(std::function< void(T &, const Event &)> callback)=0
Register a touchscreen event handler that triggers on press.
virtual void onrelease(std::function< void(T &, const Event &)> callback)=0
Register a touchscreen event handler that triggers when the widget stops being pressed.
Extended definitions for widget event handler functions.
Definition event_handlers.hpp:97
void onblur(std::function< void(const Event &)> callback)
Register a touchscreen event handler that triggers when the widget stops being pressed.
Definition event_handlers.hpp:173
void onrelease(std::function< void(const Event &)> callback)
Register a touchscreen event handler that triggers when the widget stops being pressed.
Definition event_handlers.hpp:146
void onrelease(std::function< void(T &)> callback)
Register a touchscreen event handler that triggers when the widget stops being pressed.
Definition event_handlers.hpp:137
void onpress(std::function< void(T &)> callback)
Register a touchscreen event handler that triggers on press.
Definition event_handlers.hpp:110
void onpress(std::function< void(const Event &)> callback)
Register a touchscreen event handler that triggers on press.
Definition event_handlers.hpp:119
void onrelease(std::function< void()> callback)
Register a touchscreen event handler that triggers when the widget stops being pressed.
Definition event_handlers.hpp:155
void onclick(std::function< void(const Event &)> callback)
Register a touchscreen event handler that triggers on release.
Definition event_handlers.hpp:260
void onhold(std::function< void(const Event &)> callback)
Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
Definition event_handlers.hpp:227
void onblur(std::function< void(T &)> callback)
Register a touchscreen event handler that triggers when the widget stops being pressed.
Definition event_handlers.hpp:164
void onclick(std::function< void()> callback)
Register a touchscreen event handler that triggers on release.
Definition event_handlers.hpp:272
void onhold(std::function< void()> callback)
Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
Definition event_handlers.hpp:236
void onblur(std::function< void()> callback)
Register a touchscreen event handler that triggers when the widget stops being pressed.
Definition event_handlers.hpp:182
void onhold(std::function< void(time_t)> callback)
Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
Definition event_handlers.hpp:209
void onhold(std::function< void(T &, time_t)> callback)
Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
Definition event_handlers.hpp:191
void onclick(std::function< void(T &)> callback)
Register a touchscreen event handler that triggers on release.
Definition event_handlers.hpp:248
void onhold(std::function< void(T &)> callback)
Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
Definition event_handlers.hpp:218
void onpress(std::function< void()> callback)
Register a touchscreen event handler that triggers on press.
Definition event_handlers.hpp:128
void onhold(std::function< void(const Event &, time_t)> callback)
Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
Definition event_handlers.hpp:200
A touchscreen event.
Definition event.hpp:26