ReXGlue SDK
Loading...
Searching...
No Matches
ui_event.h
Go to the documentation of this file.
1
12
13#pragma once
14
15#include <climits>
16#include <filesystem>
17
18#include <rex/input_keys.h>
19#include <rex/types.h>
20
21namespace rex::ui {
22
24class UIEvent {
25 public:
26 enum class Type : u8 {
27 kOpened,
28 kDPIChanged,
29 kMonitorUpdate,
30 kMinimized,
31 kRestored,
32 kClosing,
33 kFileDrop,
34 kResize,
35 kClose,
36 kFocus,
37 kTouch,
38 };
39
40 explicit UIEvent(Type type) : type_(type) {}
41
42 virtual ~UIEvent() = default;
43
44 Type GetType() const { return type_; }
45
51 template <typename T>
52 const T* As() const {
53 return T::Carries(type_) ? static_cast<const T*>(this) : nullptr;
54 }
55
56 private:
57 Type type_;
58};
59
61class UISetupEvent : public UIEvent {
62 public:
69 UISetupEvent(Type type, bool is_initial_setup = false)
70 : UIEvent(type), is_initial_setup_(is_initial_setup) {}
71
77 static constexpr bool Carries(Type type) {
78 return type == Type::kOpened || type == Type::kDPIChanged || type == Type::kResize ||
79 type == Type::kFocus || type == Type::kMonitorUpdate;
80 }
81
82 bool IsInitialSetup() const { return is_initial_setup_; }
83
84 private:
85 bool is_initial_setup_;
86};
87
89 public:
96 MonitorUpdateEvent(bool old_monitor_potentially_disconnected, bool is_initial_setup = false)
97 : UISetupEvent(Type::kMonitorUpdate, is_initial_setup),
98 old_monitor_potentially_disconnected_(old_monitor_potentially_disconnected) {}
99
105 static constexpr bool Carries(Type type) { return type == Type::kMonitorUpdate; }
106
107 bool IsOldMonitorPotentiallyDisconnected() const { return old_monitor_potentially_disconnected_; }
108
109 private:
110 bool old_monitor_potentially_disconnected_;
111};
112
113class FileDropEvent : public UIEvent {
114 public:
116 FileDropEvent(std::filesystem::path filename)
117 : UIEvent(Type::kFileDrop), filename_(std::move(filename)) {}
118
124 static constexpr bool Carries(Type type) { return type == Type::kFileDrop; }
125
127 const std::filesystem::path& GetFilename() const { return filename_; }
128
129 private:
130 const std::filesystem::path filename_;
131};
132
133class TouchEvent : public UIEvent {
134 public:
135 enum class Action : u8 {
136 kDown,
137 kUp,
139 kMove,
140 };
141
143 static constexpr u32 kPointerIDNone = UINT32_MAX;
144
151 TouchEvent(Type type, u32 pointer_id, Action action, f32 x, f32 y)
152 : UIEvent(type), pointer_id_(pointer_id), action_(action), x_(x), y_(y) {}
153
155 static constexpr bool Carries(Type type) { return type == Type::kTouch; }
156
158 bool IsHandled() const { return handled_; }
159
165 void SetHandled(bool value) { handled_ = value; }
166
167 u32 GetPointerID() const { return pointer_id_; }
168
169 Action GetAction() const { return action_; }
170
171 f32 GetX() const { return x_; }
172
173 f32 GetY() const { return y_; }
174
175 private:
176 bool handled_ = false;
177 u32 pointer_id_;
178 Action action_;
179 f32 x_;
180 f32 y_;
181};
182
185 public:
186 virtual ~IUIEventListener() = default;
187
193 virtual void OnUIEvent(const ui::UIEvent& event) = 0;
194
201 virtual void OnInputEvent(InputEvent& event) = 0;
202};
203
204} // namespace rex::ui
FileDropEvent(std::filesystem::path filename)
Definition ui_event.h:116
const std::filesystem::path & GetFilename() const
Definition ui_event.h:127
static constexpr bool Carries(Type type)
Definition ui_event.h:124
Definition ui_event.h:184
virtual void OnUIEvent(const ui::UIEvent &event)=0
virtual void OnInputEvent(InputEvent &event)=0
static constexpr bool Carries(Type type)
Definition ui_event.h:105
MonitorUpdateEvent(bool old_monitor_potentially_disconnected, bool is_initial_setup=false)
Definition ui_event.h:96
TouchEvent(Type type, u32 pointer_id, Action action, f32 x, f32 y)
Definition ui_event.h:151
static constexpr bool Carries(Type type)
Definition ui_event.h:155
static constexpr u32 kPointerIDNone
Definition ui_event.h:143
Action
Definition ui_event.h:135
void SetHandled(bool value)
Definition ui_event.h:165
bool IsHandled() const
Definition ui_event.h:158
Definition ui_event.h:24
Type
Definition ui_event.h:26
@ kDPIChanged
Definition ui_event.h:28
@ kFileDrop
Definition ui_event.h:33
@ kOpened
Definition ui_event.h:27
@ kMonitorUpdate
Definition ui_event.h:29
@ kFocus
Definition ui_event.h:36
@ kTouch
Definition ui_event.h:37
@ kResize
Definition ui_event.h:34
const T * As() const
Definition ui_event.h:52
static constexpr bool Carries(Type type)
Definition ui_event.h:77
UISetupEvent(Type type, bool is_initial_setup=false)
Definition ui_event.h:69
@ kCancel
Definition input_keys.h:40
Definition input_keys.h:417
Integer types, byte order wrappers and size literals.