11#include "widget_id.hpp"
14#include "keyboard_virtual_key_intf.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"
21#include "../unicode/unicode.hpp"
22#include "../geometry/geometry.hpp"
23#include "../time/time.hpp"
24#include "../macros.hpp"
28hi_export_module(hikogui.GUI : gui_event);
30hi_export
namespace hi {
inline namespace v1 {
74 hi::widget_id widget_id = {};
75 keyboard_focus_group group = keyboard_focus_group::normal;
76 keyboard_focus_direction direction = keyboard_focus_direction::here;
110 _type(gui_event_type::none),
130 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
140 gui_event(
type, std::chrono::utc_clock::now(), keyboard_modifiers::none, keyboard_state::idle)
155 keyboard_virtual_key
key,
157 hi::keyboard_state
keyboard_state = keyboard_state::idle) noexcept :
176 auto r =
gui_event{gui_event_type::mouse_enter};
183 auto r =
gui_event{gui_event_type::keyboard_grapheme};
188 [[nodiscard]]
static gui_event keyboard_partial_grapheme(hi::grapheme
grapheme)
noexcept
190 auto r =
gui_event{gui_event_type::keyboard_partial_grapheme};
197 keyboard_focus_group group = keyboard_focus_group::normal,
198 keyboard_focus_direction direction = keyboard_focus_direction::here)
noexcept
201 r.keyboard_target().widget_id = id;
202 r.keyboard_target().group = group;
203 r.keyboard_target().direction = direction;
215 r.clipboard_data() = text;
233 auto const previous_variant = variant();
236 if (previous_variant != variant()) {
242 _data = hi::grapheme{};
245 _data = keyboard_virtual_key{};
267 return std::get<mouse_event_data>(_data);
277 return std::get<mouse_event_data>(_data);
284 [[nodiscard]] keyboard_virtual_key&
key() noexcept
287 return std::get<keyboard_virtual_key>(_data);
294 [[nodiscard]] keyboard_virtual_key
const&
key() const noexcept
297 return std::get<keyboard_virtual_key>(_data);
307 return std::get<hi::grapheme>(_data);
314 [[nodiscard]] hi::grapheme
const&
grapheme() const noexcept
317 return std::get<hi::grapheme>(_data);
323 return std::get<aarectangle>(_data);
329 return std::get<aarectangle>(_data);
332 [[nodiscard]] keyboard_target_data& keyboard_target() noexcept
335 return std::get<keyboard_target_data>(_data);
338 [[nodiscard]] keyboard_target_data
const& keyboard_target() const noexcept
341 return std::get<keyboard_target_data>(_data);
344 [[nodiscard]] gstring& clipboard_data() noexcept
347 return std::get<gstring>(_data);
350 [[nodiscard]] gstring
const& clipboard_data() const noexcept
353 return std::get<gstring>(_data);
356 [[nodiscard]]
constexpr bool operator==(
gui_event_type event_type)
const noexcept
358 return type() == event_type;
361 [[nodiscard]]
constexpr bool operator==(
gui_event_variant event_variant)
const noexcept
363 return variant() == event_variant;
366 [[nodiscard]]
constexpr bool empty() const noexcept
368 return type() == gui_event_type::none;
371 constexpr operator bool() const noexcept
386 return type() == mouse_up and
mouse().
cause.left_button and active_area.contains(
mouse().position);
410 r.mouse().down_position = transform * rhs.mouse().down_position;
417 std::variant<mouse_event_data, keyboard_virtual_key, keyboard_target_data, hi::grapheme, aarectangle, gstring>;
427struct std::formatter<
hi::gui_event, char> : std::formatter<std::string_view, char> {
430 return std::formatter<std::string_view, char>::format(hi::gui_event_type_metadata[t.
type()], fc);
Definition of a GUI event variant.
Definition of GUI event type.
gui_event_type
GUI event type.
Definition gui_event_type.hpp:24
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:54
gui_event_variant
A granular gui event type.
Definition gui_event_variant.hpp:21
@ 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.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:25
Definition translate2.hpp:18
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:27
Information for a mouse event.
Definition gui_event.hpp:35
point2 position
The current position of the mouse pointer.
Definition gui_event.hpp:44
uint8_t click_count
Number of clicks from the last button clicked.
Definition gui_event.hpp:70
vector2 wheel_delta
Change in wheel rotation, in points (pt).
Definition gui_event.hpp:58
hi::hitbox hitbox
Information about which widget is underneath the mouse pointer.
Definition gui_event.hpp:38
mouse_buttons down
Buttons that are also held down.
Definition gui_event.hpp:66
mouse_buttons cause
Buttons which have caused this event.
Definition gui_event.hpp:62
point2 down_position
The position the last time a button was pressed.
Definition gui_event.hpp:52
Definition gui_event.hpp:73
A user interface event.
Definition gui_event.hpp:82
utc_nanoseconds time_point
The time when the event was created.
Definition gui_event.hpp:86
constexpr vector2 drag_delta() const noexcept
Get the location of the mouse relative to the start of a drag.
Definition gui_event.hpp:391
constexpr friend gui_event operator*(translate2 const &transform, gui_event const &rhs) noexcept
Transform a gui-event to another coordinate system.
Definition gui_event.hpp:405
mouse_event_data const & mouse() const noexcept
Get the mouse event information.
Definition gui_event.hpp:274
static gui_event make_clipboard_event(gui_event_type type, gstring_view text) noexcept
Create clipboard event.
Definition gui_event.hpp:212
constexpr void set_type(gui_event_type type) noexcept
Change the type of the gui_event.
Definition gui_event.hpp:231
constexpr gui_event() noexcept
Create an empty GUI event.
Definition gui_event.hpp:120
hi::grapheme & grapheme() noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:304
keyboard_modifiers keyboard_modifiers
Keyboard modifiers: shift, ctrl, alt, etc.
Definition gui_event.hpp:92
static gui_event make_mouse_enter(point2 position) noexcept
Create a mouse enter event.
Definition gui_event.hpp:174
gui_event(gui_event_type type, aarectangle rectangle) noexcept
Create a rectangle event.
Definition gui_event.hpp:139
keyboard_state keyboard_state
State of the keyboard; caps-lock, num-lock, scroll-lock.
Definition gui_event.hpp:96
hi::grapheme const & grapheme() const noexcept
Get the grapheme entered on the keyboard.
Definition gui_event.hpp:314
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:383
constexpr gui_event_type type() const noexcept
Get the event type.
Definition gui_event.hpp:221
keyboard_virtual_key const & key() const noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:294
mouse_event_data & mouse() noexcept
Get the mouse event information.
Definition gui_event.hpp:264
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:153
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:105
gui_event(gui_event_type type) noexcept
Create am empty GUI event.
Definition gui_event.hpp:129
keyboard_virtual_key & key() noexcept
Get the key from the keyboard event.
Definition gui_event.hpp:284