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 "../text/module.hpp"
21#include "../unicode/module.hpp"
22#include "../geometry/module.hpp"
23#include "../chrono.hpp"
27namespace hi {
inline namespace v1 {
67 hi::widget_id widget_id = {};
68 keyboard_focus_group group = keyboard_focus_group::normal;
69 keyboard_focus_direction direction = keyboard_focus_direction::here;
103 _type(gui_event_type::none),
123 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
133 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
136 this->rectangle() = rectangle;
148 keyboard_virtual_key
key,
150 hi::keyboard_state
keyboard_state = keyboard_state::idle) noexcept :
169 auto r =
gui_event{gui_event_type::mouse_enter};
176 auto r =
gui_event{gui_event_type::keyboard_grapheme};
181 [[nodiscard]]
static gui_event keyboard_partial_grapheme(hi::grapheme
grapheme)
noexcept
183 auto r =
gui_event{gui_event_type::keyboard_partial_grapheme};
190 keyboard_focus_group group = keyboard_focus_group::normal,
191 keyboard_focus_direction direction = keyboard_focus_direction::here)
noexcept
194 r.keyboard_target().widget_id = id;
195 r.keyboard_target().group = group;
196 r.keyboard_target().direction = direction;
208 r.clipboard_data() =
text;
226 hilet previous_variant = variant();
229 if (previous_variant != variant()) {
235 _data = hi::grapheme{};
238 _data = keyboard_virtual_key{};
260 return std::get<mouse_event_data>(_data);
270 return std::get<mouse_event_data>(_data);
277 [[nodiscard]] keyboard_virtual_key&
key() noexcept
280 return std::get<keyboard_virtual_key>(_data);
287 [[nodiscard]] keyboard_virtual_key
const&
key() const noexcept
290 return std::get<keyboard_virtual_key>(_data);
300 return std::get<hi::grapheme>(_data);
307 [[nodiscard]] hi::grapheme
const&
grapheme() const noexcept
310 return std::get<hi::grapheme>(_data);
316 return std::get<aarectanglei>(_data);
319 [[nodiscard]] aarectanglei
const& rectangle() const noexcept
322 return std::get<aarectanglei>(_data);
325 [[nodiscard]] keyboard_target_data& keyboard_target() noexcept
328 return std::get<keyboard_target_data>(_data);
331 [[nodiscard]] keyboard_target_data
const& keyboard_target() const noexcept
334 return std::get<keyboard_target_data>(_data);
337 [[nodiscard]]
hi::text& clipboard_data() noexcept
340 return std::get<hi::text>(_data);
343 [[nodiscard]]
hi::text const& clipboard_data() const noexcept
346 return std::get<hi::text>(_data);
349 [[nodiscard]]
constexpr bool operator==(
gui_event_type event_type)
const noexcept
351 return type() == event_type;
354 [[nodiscard]]
constexpr bool operator==(
gui_event_variant event_variant)
const noexcept
356 return variant() == event_variant;
359 [[nodiscard]]
constexpr bool empty() const noexcept
361 return type() == gui_event_type::none;
364 constexpr operator bool() const noexcept
379 return type() == mouse_up and
mouse().
cause.left_button and active_area.contains(
mouse().position);
403 r.mouse().down_position = transform * rhs.mouse().down_position;
410 std::variant<mouse_event_data, keyboard_virtual_key, keyboard_target_data, hi::grapheme, aarectanglei, hi::text>;
418template<
typename CharT>
419struct std::formatter<
hi::gui_event, CharT> : std::formatter<std::string_view, CharT> {
422 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:199
#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:32
uint8_t click_count
Number of clicks from the last button clicked.
Definition gui_event.hpp:63
point2i position
The current position of the mouse pointer.
Definition gui_event.hpp:37
mouse_buttons down
Buttons that are also held down.
Definition gui_event.hpp:59
mouse_buttons cause
Buttons which have caused this event.
Definition gui_event.hpp:55
point2i down_position
The position the last time a button was pressed.
Definition gui_event.hpp:45
vector2i wheel_delta
Change in wheel rotation, in points (pt).
Definition gui_event.hpp:51
Definition gui_event.hpp:66
A user interface event.
Definition gui_event.hpp:75
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:398
utc_nanoseconds time_point
The time when the event was created.
Definition gui_event.hpp:79
static gui_event make_mouse_enter(point2i position) noexcept
Create a mouse enter event.
Definition gui_event.hpp:167
gui_event(gui_event_type type, aarectanglei rectangle) noexcept
Create a rectangle event.
Definition gui_event.hpp:132
static gui_event make_clipboard_event(gui_event_type type, hi::text text) noexcept
Create clipboard event.
Definition gui_event.hpp:205
mouse_event_data const & mouse() const noexcept
Get the mouse event information.
Definition gui_event.hpp:267
constexpr void set_type(gui_event_type type) noexcept
Change the type of the gui_event.
Definition gui_event.hpp:224
constexpr gui_event() noexcept
Create an empty GUI event.
Definition gui_event.hpp:113
hi::grapheme & grapheme() noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:297
keyboard_modifiers keyboard_modifiers
Keyboard modifiers: shift, ctrl, alt, etc.
Definition gui_event.hpp:85
keyboard_state keyboard_state
State of the keyboard; caps-lock, num-lock, scroll-lock.
Definition gui_event.hpp:89
hi::grapheme const & grapheme() const noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:307
constexpr vector2i drag_delta() const noexcept
Get the location of the mouse relative to the start of a drag.
Definition gui_event.hpp:384
constexpr gui_event_type type() const noexcept
Get the event type.
Definition gui_event.hpp:214
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:376
keyboard_virtual_key const & key() const noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:287
mouse_event_data & mouse() noexcept
Get the mouse event information.
Definition gui_event.hpp:257
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:146
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:98
gui_event(gui_event_type type) noexcept
Create am empty GUI event.
Definition gui_event.hpp:122
keyboard_virtual_key & key() noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:277