13#include "keyboard_virtual_key.hpp"
14#include "keyboard_state.hpp"
15#include "keyboard_modifiers.hpp"
16#include "keyboard_focus_group.hpp"
17#include "keyboard_focus_direction.hpp"
18#include "mouse_buttons.hpp"
19#include "../unicode/grapheme.hpp"
20#include "../geometry/vector.hpp"
21#include "../geometry/point.hpp"
22#include "../geometry/transform.hpp"
23#include "../chrono.hpp"
26namespace hi {
inline namespace v1 {
69 keyboard_focus_group group = keyboard_focus_group::normal;
70 keyboard_focus_direction direction = keyboard_focus_direction::here;
104 _type(gui_event_type::none),
124 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
134 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
137 this->rectangle() = rectangle;
149 keyboard_virtual_key
key,
151 hi::keyboard_state
keyboard_state = keyboard_state::idle) noexcept :
170 auto r =
gui_event{gui_event_type::mouse_enter};
177 auto r =
gui_event{gui_event_type::keyboard_grapheme};
182 [[nodiscard]]
static gui_event keyboard_partial_grapheme(hi::grapheme
grapheme)
noexcept
184 auto r =
gui_event{gui_event_type::keyboard_partial_grapheme};
190 widget
const *widget,
191 keyboard_focus_group group = keyboard_focus_group::normal,
192 keyboard_focus_direction direction = keyboard_focus_direction::here)
noexcept
195 r.keyboard_target().widget = widget;
196 r.keyboard_target().group = group;
197 r.keyboard_target().direction = direction;
204 r.keyboard_target().widget = widget;
216 r.clipboard_data() = text;
234 hilet previous_variant = variant();
237 if (previous_variant != variant()) {
243 _data = hi::grapheme{};
246 _data = keyboard_virtual_key{};
252 _data = aarectangle{};
268 return std::get<mouse_event_data>(_data);
278 return std::get<mouse_event_data>(_data);
285 [[nodiscard]] keyboard_virtual_key&
key() noexcept
288 return std::get<keyboard_virtual_key>(_data);
295 [[nodiscard]] keyboard_virtual_key
const&
key() const noexcept
298 return std::get<keyboard_virtual_key>(_data);
308 return std::get<hi::grapheme>(_data);
315 [[nodiscard]] hi::grapheme
const&
grapheme() const noexcept
318 return std::get<hi::grapheme>(_data);
321 [[nodiscard]] aarectangle& rectangle() noexcept
324 return std::get<aarectangle>(_data);
327 [[nodiscard]] aarectangle
const& rectangle() const noexcept
330 return std::get<aarectangle>(_data);
333 [[nodiscard]] keyboard_target_data& keyboard_target() noexcept
336 return std::get<keyboard_target_data>(_data);
339 [[nodiscard]] keyboard_target_data
const& keyboard_target() const noexcept
342 return std::get<keyboard_target_data>(_data);
345 [[nodiscard]]
std::string& clipboard_data() noexcept
348 return std::get<std::string>(_data);
351 [[nodiscard]]
std::string const& clipboard_data() const noexcept
354 return std::get<std::string>(_data);
357 [[nodiscard]]
constexpr bool operator==(
gui_event_type event_type)
const noexcept
359 return type() == event_type;
362 [[nodiscard]]
constexpr bool operator==(
gui_event_variant event_variant)
const noexcept
364 return variant() == event_variant;
367 [[nodiscard]]
constexpr bool empty() const noexcept
369 return type() == gui_event_type::none;
372 constexpr operator bool() const noexcept
387 return type() == mouse_up and
mouse().
cause.left_button and active_area.contains(
mouse().position);
410 r.
mouse().
position = point2{transform * rhs.mouse().position};
411 r.mouse().down_position = point2{transform * rhs.mouse().down_position};
412 r.mouse().wheel_delta = vector2{transform * rhs.mouse().wheel_delta};
419 std::variant<mouse_event_data, keyboard_virtual_key, keyboard_target_data, hi::grapheme, aarectangle, std::string>;
427template<
typename CharT>
428struct std::formatter<
hi::gui_event, CharT> : std::formatter<std::string_view, CharT> {
431 return std::formatter<std::string_view, CharT>::format(hi::gui_event_type_metadata[t.
type()], fc);
#define hi_assert(expression)
Assert if expression is true.
Definition assert.hpp:86
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Definition of a GUI event variant.
Definition of GUI event type.
gui_event_type
GUI event type.
Definition gui_event_type.hpp:22
constexpr gui_event_variant to_gui_event_variant(gui_event_type type) noexcept
Convert a gui event type, to an gui event variant.
Definition gui_event_variant.hpp:51
gui_event_variant
A granular gui event type.
Definition gui_event_variant.hpp:18
@ window_set_keyboard_target
Change the keyboard target widget for this window.
@ window_remove_keyboard_target
Remove a widget as keyboard target.
@ keyboard
The gui_event has keyboard data.
@ mouse
The gui_event has mouse data.
@ keyboard_target
The gui_event has keyboard target data.
@ grapheme
The gui_event has grapheme data.
@ rectangle
The gui_event has rectangle data.
@ clipboard_data
The gui_event has clipboard data.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
Information for a mouse event.
Definition gui_event.hpp:31
point2 position
The current position of the mouse pointer.
Definition gui_event.hpp:36
uint8_t click_count
Number of clicks from the last button clicked.
Definition gui_event.hpp:62
vector2 wheel_delta
Change in wheel rotation, in points (pt).
Definition gui_event.hpp:50
mouse_buttons down
Buttons that are also held down.
Definition gui_event.hpp:58
mouse_buttons cause
Buttons which have caused this event.
Definition gui_event.hpp:54
point2 down_position
The position the last time a button was pressed.
Definition gui_event.hpp:44
Definition gui_event.hpp:67
A user interface event.
Definition gui_event.hpp:76
utc_nanoseconds time_point
The time when the event was created.
Definition gui_event.hpp:80
constexpr vector2 drag_delta() const noexcept
Get the location of the mouse relative to the start of a drag.
Definition gui_event.hpp:392
mouse_event_data const & mouse() const noexcept
Get the mouse event information.
Definition gui_event.hpp:275
constexpr void set_type(gui_event_type type) noexcept
Change the type of the gui_event.
Definition gui_event.hpp:232
constexpr gui_event() noexcept
Create an empty GUI event.
Definition gui_event.hpp:114
hi::grapheme & grapheme() noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:305
keyboard_modifiers keyboard_modifiers
Keyboard modifiers: shift, ctrl, alt, etc.
Definition gui_event.hpp:86
static gui_event make_mouse_enter(point2 position) noexcept
Create a mouse enter event.
Definition gui_event.hpp:168
gui_event(gui_event_type type, aarectangle rectangle) noexcept
Create a rectangle event.
Definition gui_event.hpp:133
static gui_event make_clipboard_event(gui_event_type type, std::string_view text) noexcept
Create clipboard event.
Definition gui_event.hpp:213
keyboard_state keyboard_state
State of the keyboard; caps-lock, num-lock, scroll-lock.
Definition gui_event.hpp:90
hi::grapheme const & grapheme() const noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:315
constexpr bool is_left_button_up(aarectangle active_area) const noexcept
Check if this event is for a left-button-up event while the mouse pointer is in the given area.
Definition gui_event.hpp:384
constexpr gui_event_type type() const noexcept
Get the event type.
Definition gui_event.hpp:222
keyboard_virtual_key const & key() const noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:295
mouse_event_data & mouse() noexcept
Get the mouse event information.
Definition gui_event.hpp:265
constexpr friend gui_event operator*(geo::transformer auto const &transform, gui_event const &rhs) noexcept
Transform a gui-event to another coordinate system.
Definition gui_event.hpp:406
gui_event(gui_event_type type, keyboard_virtual_key key, hi::keyboard_modifiers keyboard_modifiers=keyboard_modifiers::none, hi::keyboard_state keyboard_state=keyboard_state::idle) noexcept
Create a GUI event.
Definition gui_event.hpp:147
constexpr gui_event(gui_event_type type, utc_nanoseconds time_point, hi::keyboard_modifiers keyboard_modifiers, hi::keyboard_state keyboard_state) noexcept
Create a GUI event.
Definition gui_event.hpp:99
gui_event(gui_event_type type) noexcept
Create am empty GUI event.
Definition gui_event.hpp:123
keyboard_virtual_key & key() noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:285
An interactive graphical object as part of the user-interface.
Definition widget.hpp:45