11#include "widget_id.hpp"
14#include "keyboard_virtual_key.hpp"
15#include "keyboard_state.hpp"
16#include "keyboard_modifiers.hpp"
17#include "keyboard_focus_group.hpp"
18#include "keyboard_focus_direction.hpp"
19#include "mouse_buttons.hpp"
20#include "../unicode/grapheme.hpp"
21#include "../geometry/module.hpp"
22#include "../chrono.hpp"
26namespace hi {
inline namespace v1 {
66 hi::widget_id widget_id = {};
67 keyboard_focus_group group = keyboard_focus_group::normal;
68 keyboard_focus_direction direction = keyboard_focus_direction::here;
102 _type(gui_event_type::none),
122 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
132 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
135 this->rectangle() = rectangle;
147 keyboard_virtual_key
key,
149 hi::keyboard_state
keyboard_state = keyboard_state::idle) noexcept :
168 auto r =
gui_event{gui_event_type::mouse_enter};
175 auto r =
gui_event{gui_event_type::keyboard_grapheme};
180 [[nodiscard]]
static gui_event keyboard_partial_grapheme(hi::grapheme
grapheme)
noexcept
182 auto r =
gui_event{gui_event_type::keyboard_partial_grapheme};
189 keyboard_focus_group group = keyboard_focus_group::normal,
190 keyboard_focus_direction direction = keyboard_focus_direction::here)
noexcept
193 r.keyboard_target().widget_id = id;
194 r.keyboard_target().group = group;
195 r.keyboard_target().direction = direction;
207 r.clipboard_data() = text;
225 hilet previous_variant = variant();
228 if (previous_variant != variant()) {
234 _data = hi::grapheme{};
237 _data = keyboard_virtual_key{};
259 return std::get<mouse_event_data>(_data);
269 return std::get<mouse_event_data>(_data);
276 [[nodiscard]] keyboard_virtual_key&
key() noexcept
279 return std::get<keyboard_virtual_key>(_data);
286 [[nodiscard]] keyboard_virtual_key
const&
key() const noexcept
289 return std::get<keyboard_virtual_key>(_data);
299 return std::get<hi::grapheme>(_data);
306 [[nodiscard]] hi::grapheme
const&
grapheme() const noexcept
309 return std::get<hi::grapheme>(_data);
315 return std::get<aarectanglei>(_data);
318 [[nodiscard]] aarectanglei
const& rectangle() const noexcept
321 return std::get<aarectanglei>(_data);
324 [[nodiscard]] keyboard_target_data& keyboard_target() noexcept
327 return std::get<keyboard_target_data>(_data);
330 [[nodiscard]] keyboard_target_data
const& keyboard_target() const noexcept
333 return std::get<keyboard_target_data>(_data);
336 [[nodiscard]]
std::string& clipboard_data() noexcept
339 return std::get<std::string>(_data);
342 [[nodiscard]]
std::string const& clipboard_data() const noexcept
345 return std::get<std::string>(_data);
348 [[nodiscard]]
constexpr bool operator==(
gui_event_type event_type)
const noexcept
350 return type() == event_type;
353 [[nodiscard]]
constexpr bool operator==(
gui_event_variant event_variant)
const noexcept
355 return variant() == event_variant;
358 [[nodiscard]]
constexpr bool empty() const noexcept
360 return type() == gui_event_type::none;
363 constexpr operator bool() const noexcept
378 return type() == mouse_up and
mouse().
cause.left_button and active_area.contains(
mouse().position);
402 r.mouse().down_position = transform * rhs.mouse().down_position;
409 std::variant<mouse_event_data, keyboard_virtual_key, keyboard_target_data, hi::grapheme, aarectanglei, std::string>;
417template<
typename CharT>
418struct std::formatter<
hi::gui_event, CharT> : std::formatter<std::string_view, CharT> {
421 return std::formatter<std::string_view, CharT>::format(hi::gui_event_type_metadata[t.
type()], fc);
Definition of a GUI event variant.
Definition of GUI event type.
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:184
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
gui_event_type
GUI event type.
Definition gui_event_type.hpp:21
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.
@ 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:13
geometry/margins.hpp
Definition cache.hpp:11
Information for a mouse event.
Definition gui_event.hpp:31
uint8_t click_count
Number of clicks from the last button clicked.
Definition gui_event.hpp:62
point2i position
The current position of the mouse pointer.
Definition gui_event.hpp:36
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
point2i down_position
The position the last time a button was pressed.
Definition gui_event.hpp:44
vector2i wheel_delta
Change in wheel rotation, in points (pt).
Definition gui_event.hpp:50
Definition gui_event.hpp:65
A user interface event.
Definition gui_event.hpp:74
constexpr friend gui_event operator*(translate2i const &transform, gui_event const &rhs) noexcept
Transform a gui-event to another coordinate system.
Definition gui_event.hpp:397
utc_nanoseconds time_point
The time when the event was created.
Definition gui_event.hpp:78
static gui_event make_mouse_enter(point2i position) noexcept
Create a mouse enter event.
Definition gui_event.hpp:166
gui_event(gui_event_type type, aarectanglei rectangle) noexcept
Create a rectangle event.
Definition gui_event.hpp:131
mouse_event_data const & mouse() const noexcept
Get the mouse event information.
Definition gui_event.hpp:266
constexpr void set_type(gui_event_type type) noexcept
Change the type of the gui_event.
Definition gui_event.hpp:223
constexpr gui_event() noexcept
Create an empty GUI event.
Definition gui_event.hpp:112
hi::grapheme & grapheme() noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:296
keyboard_modifiers keyboard_modifiers
Keyboard modifiers: shift, ctrl, alt, etc.
Definition gui_event.hpp:84
static gui_event make_clipboard_event(gui_event_type type, std::string_view text) noexcept
Create clipboard event.
Definition gui_event.hpp:204
keyboard_state keyboard_state
State of the keyboard; caps-lock, num-lock, scroll-lock.
Definition gui_event.hpp:88
hi::grapheme const & grapheme() const noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:306
constexpr vector2i drag_delta() const noexcept
Get the location of the mouse relative to the start of a drag.
Definition gui_event.hpp:383
constexpr gui_event_type type() const noexcept
Get the event type.
Definition gui_event.hpp:213
constexpr bool is_left_button_up(aarectanglei 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:375
keyboard_virtual_key const & key() const noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:286
mouse_event_data & mouse() noexcept
Get the mouse event information.
Definition gui_event.hpp:256
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:145
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:97
gui_event(gui_event_type type) noexcept
Create am empty GUI event.
Definition gui_event.hpp:121
keyboard_virtual_key & key() noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:276