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/translate.hpp"
23#include "../chrono.hpp"
27namespace hi {
inline namespace v1 {
70 keyboard_focus_group group = keyboard_focus_group::normal;
71 keyboard_focus_direction direction = keyboard_focus_direction::here;
105 _type(gui_event_type::none),
125 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
135 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
138 this->rectangle() = rectangle;
150 keyboard_virtual_key
key,
152 hi::keyboard_state
keyboard_state = keyboard_state::idle) noexcept :
171 auto r =
gui_event{gui_event_type::mouse_enter};
178 auto r =
gui_event{gui_event_type::keyboard_grapheme};
183 [[nodiscard]]
static gui_event keyboard_partial_grapheme(hi::grapheme
grapheme)
noexcept
185 auto r =
gui_event{gui_event_type::keyboard_partial_grapheme};
191 widget
const *widget,
192 keyboard_focus_group group = keyboard_focus_group::normal,
193 keyboard_focus_direction direction = keyboard_focus_direction::here)
noexcept
196 r.keyboard_target().widget = widget;
197 r.keyboard_target().group = group;
198 r.keyboard_target().direction = direction;
210 r.clipboard_data() = text;
228 hilet previous_variant = variant();
231 if (previous_variant != variant()) {
237 _data = hi::grapheme{};
240 _data = keyboard_virtual_key{};
262 return std::get<mouse_event_data>(_data);
272 return std::get<mouse_event_data>(_data);
279 [[nodiscard]] keyboard_virtual_key&
key() noexcept
282 return std::get<keyboard_virtual_key>(_data);
289 [[nodiscard]] keyboard_virtual_key
const&
key() const noexcept
292 return std::get<keyboard_virtual_key>(_data);
302 return std::get<hi::grapheme>(_data);
309 [[nodiscard]] hi::grapheme
const&
grapheme() const noexcept
312 return std::get<hi::grapheme>(_data);
318 return std::get<aarectanglei>(_data);
321 [[nodiscard]] aarectanglei
const& rectangle() const noexcept
324 return std::get<aarectanglei>(_data);
327 [[nodiscard]] keyboard_target_data& keyboard_target() noexcept
330 return std::get<keyboard_target_data>(_data);
333 [[nodiscard]] keyboard_target_data
const& keyboard_target() const noexcept
336 return std::get<keyboard_target_data>(_data);
339 [[nodiscard]]
std::string& clipboard_data() noexcept
342 return std::get<std::string>(_data);
345 [[nodiscard]]
std::string const& clipboard_data() const noexcept
348 return std::get<std::string>(_data);
351 [[nodiscard]]
constexpr bool operator==(
gui_event_type event_type)
const noexcept
353 return type() == event_type;
356 [[nodiscard]]
constexpr bool operator==(
gui_event_variant event_variant)
const noexcept
358 return variant() == event_variant;
361 [[nodiscard]]
constexpr bool empty() const noexcept
363 return type() == gui_event_type::none;
366 constexpr operator bool() const noexcept
381 return type() == mouse_up and
mouse().
cause.left_button and active_area.contains(
mouse().position);
405 r.mouse().down_position = transform * rhs.mouse().down_position;
412 std::variant<mouse_event_data, keyboard_virtual_key, keyboard_target_data, hi::grapheme, aarectanglei, std::string>;
420template<
typename CharT>
421struct std::formatter<
hi::gui_event, CharT> : std::formatter<std::string_view, CharT> {
424 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:87
#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.
@ 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
geometry/margins.hpp
Definition assert.hpp:18
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:68
A user interface event.
Definition gui_event.hpp:77
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:400
utc_nanoseconds time_point
The time when the event was created.
Definition gui_event.hpp:81
static gui_event make_mouse_enter(point2i position) noexcept
Create a mouse enter event.
Definition gui_event.hpp:169
gui_event(gui_event_type type, aarectanglei rectangle) noexcept
Create a rectangle event.
Definition gui_event.hpp:134
mouse_event_data const & mouse() const noexcept
Get the mouse event information.
Definition gui_event.hpp:269
constexpr void set_type(gui_event_type type) noexcept
Change the type of the gui_event.
Definition gui_event.hpp:226
constexpr gui_event() noexcept
Create an empty GUI event.
Definition gui_event.hpp:115
hi::grapheme & grapheme() noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:299
keyboard_modifiers keyboard_modifiers
Keyboard modifiers: shift, ctrl, alt, etc.
Definition gui_event.hpp:87
static gui_event make_clipboard_event(gui_event_type type, std::string_view text) noexcept
Create clipboard event.
Definition gui_event.hpp:207
keyboard_state keyboard_state
State of the keyboard; caps-lock, num-lock, scroll-lock.
Definition gui_event.hpp:91
hi::grapheme const & grapheme() const noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:309
constexpr vector2i drag_delta() const noexcept
Get the location of the mouse relative to the start of a drag.
Definition gui_event.hpp:386
constexpr gui_event_type type() const noexcept
Get the event type.
Definition gui_event.hpp:216
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:378
keyboard_virtual_key const & key() const noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:289
mouse_event_data & mouse() noexcept
Get the mouse event information.
Definition gui_event.hpp:259
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:148
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:100
gui_event(gui_event_type type) noexcept
Create am empty GUI event.
Definition gui_event.hpp:124
keyboard_virtual_key & key() noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:279
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46