ttx 0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
key_event.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/container/string/string.h"
4#include "di/container/string/string_view.h"
5#include "di/reflect/enumerator.h"
6#include "di/reflect/field.h"
7#include "di/reflect/prelude.h"
8#include "ttx/key.h"
9#include "ttx/modifiers.h"
10
11namespace ttx {
12enum class KeyEventType {
13 Press = 1,
14 Repeat = 2,
16};
17
18constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<KeyEventType>) {
19 using enum KeyEventType;
20 return di::make_enumerators<"KeyEventType">(di::enumerator<"Press", Press>, di::enumerator<"Repeat", Repeat>,
21 di::enumerator<"Release", Release>);
22}
23
24class KeyEvent {
25public:
26 constexpr static auto key_down(Key key, di::String text = {}, Modifiers modifiers = Modifiers::None,
27 c32 shifted_key = 0, c32 base_layout_key = 0) -> KeyEvent {
29 }
30
32 c32 shifted_key = 0, c32 base_layout_key = 0)
33 : m_type(type)
34 , m_modifiers(modifiers)
35 , m_key(key)
36 , m_shifted_key(shifted_key)
37 , m_base_layout_key(base_layout_key)
38 , m_text(di::move(text)) {}
39
40 constexpr auto type() const -> KeyEventType { return m_type; }
41 constexpr auto modifiers() const -> Modifiers { return m_modifiers; }
42 constexpr auto key() const -> Key { return m_key; }
43 constexpr auto shifted_key() const -> c32 { return m_shifted_key; }
44 constexpr auto base_layout_key() const -> c32 { return m_base_layout_key; }
45 constexpr auto text() const -> di::StringView { return m_text; }
46
47 auto operator==(KeyEvent const&) const -> bool = default;
48
49private:
50 constexpr friend auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<KeyEvent>) {
51 return di::make_fields<"KeyEvent">(
52 di::field<"type", &KeyEvent::m_type>, di::field<"modifers", &KeyEvent::m_modifiers>,
53 di::field<"key", &KeyEvent::m_key>, di::field<"shifted_key", &KeyEvent::m_shifted_key>,
54 di::field<"base_layout_key", &KeyEvent::m_base_layout_key>, di::field<"text", &KeyEvent::m_text>);
55 }
56
58 Modifiers m_modifiers { Modifiers::None };
59 Key m_key { Key::None };
60 c32 m_shifted_key { 0 };
61 c32 m_base_layout_key { 0 };
62 di::String m_text;
63};
64}
Definition key_event.h:24
auto operator==(KeyEvent const &) const -> bool=default
constexpr auto modifiers() const -> Modifiers
Definition key_event.h:41
constexpr auto shifted_key() const -> c32
Definition key_event.h:43
constexpr auto key() const -> Key
Definition key_event.h:42
constexpr KeyEvent(KeyEventType type, Key key, di::String text={}, Modifiers modifiers=Modifiers::None, c32 shifted_key=0, c32 base_layout_key=0)
Definition key_event.h:31
constexpr auto text() const -> di::StringView
Definition key_event.h:45
constexpr friend auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< KeyEvent >)
Definition key_event.h:50
constexpr auto type() const -> KeyEventType
Definition key_event.h:40
constexpr auto base_layout_key() const -> c32
Definition key_event.h:44
static constexpr auto key_down(Key key, di::String text={}, Modifiers modifiers=Modifiers::None, c32 shifted_key=0, c32 base_layout_key=0) -> KeyEvent
Definition key_event.h:26
Definition cursor_style.h:5
Modifiers
Definition modifiers.h:9
@ None
Definition modifiers.h:10
KeyEventType
Definition key_event.h:12
@ Press
Definition key_event.h:13
@ Repeat
Definition key_event.h:14
@ Release
Definition key_event.h:15
Key
Definition key.h:8
@ None
Definition key.h:9
constexpr auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< CursorStyle >)
Definition cursor_style.h:16