HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
command.hpp
1// Copyright Take Vos 2020-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#include "required.hpp"
6#include <string>
7#include <string_view>
8#include <ostream>
9
10#pragma once
11
12namespace tt {
13
14enum class command {
15 unknown,
16 text_cursor_char_left,
17 text_cursor_char_right,
18 text_cursor_word_left,
19 text_cursor_word_right,
20 text_cursor_line_begin,
21 text_cursor_line_end,
22 text_select_char_left,
23 text_select_char_right,
24 text_select_word,
25 text_select_word_left,
26 text_select_word_right,
27 text_select_line_begin,
28 text_select_line_end,
29 text_select_document,
30 text_mode_insert,
31 text_delete_char_prev,
32 text_delete_char_next,
33 text_edit_paste,
34 text_edit_copy,
35 text_edit_cut,
36 text_undo,
37 text_redo,
38 gui_keyboard_enter,
39 gui_keyboard_exit,
40 gui_mouse_enter,
41 gui_mouse_exit,
42 gui_widget_next,
43 gui_widget_prev,
44 gui_menu_next,
45 gui_menu_prev,
46 gui_toolbar_next,
47 gui_toolbar_prev,
48 gui_activate,
49 gui_enter,
50 gui_escape,
51};
52
53constexpr char const *to_const_string(command rhs) noexcept
54{
55 switch (rhs) {
56 case command::unknown: return "unknown";
57 case command::text_cursor_char_left: return "text_cursor_char_left";
58 case command::text_cursor_char_right: return "text_cursor_char_right";
59 case command::text_cursor_word_left: return "text_cursor_word_left";
60 case command::text_cursor_word_right: return "text_cursor_word_right";
61 case command::text_cursor_line_begin: return "text_cursor_line_begin";
62 case command::text_cursor_line_end: return "text_cursor_line_end";
63 case command::text_select_char_left: return "text_select_char_left";
64 case command::text_select_char_right: return "text_select_char_right";
65 case command::text_select_word: return "text_select_word";
66 case command::text_select_word_left: return "text_select_word_left";
67 case command::text_select_word_right: return "text_select_word_right";
68 case command::text_select_line_begin: return "text_select_line_begin";
69 case command::text_select_line_end: return "text_select_line_end";
70 case command::text_select_document: return "text_select_document";
71 case command::text_mode_insert: return "text_mode_insert";
72 case command::text_delete_char_prev: return "text_delete_char_prev";
73 case command::text_delete_char_next: return "text_delete_char_next";
74 case command::text_edit_paste: return "text_edit_paste";
75 case command::text_edit_copy: return "text_edit_copy";
76 case command::text_edit_cut: return "text_edit_cut";
77 case command::text_undo: return "text_undo";
78 case command::text_redo: return "text_redo";
79 case command::gui_keyboard_enter: return "gui_keyboard_enter";
80 case command::gui_keyboard_exit: return "gui_keyboard_exit";
81 case command::gui_mouse_enter: return "gui_mouse_enter";
82 case command::gui_mouse_exit: return "gui_mouse_exit";
83 case command::gui_widget_next: return "gui_widget_next";
84 case command::gui_widget_prev: return "gui_widget_prev";
85 case command::gui_menu_next: return "gui_menu_next";
86 case command::gui_menu_prev: return "gui_menu_prev";
87 case command::gui_toolbar_next: return "gui_toolbar_next";
88 case command::gui_toolbar_prev: return "gui_toolbar_prev";
89 case command::gui_activate: return "gui_activate";
90 case command::gui_enter: return "gui_enter";
91 case command::gui_escape: return "gui_escape";
92 default:
93 tt_no_default();
94 }
95}
96
97inline std::string to_string(command rhs) noexcept {
98 return to_const_string(rhs);
99}
100
101inline std::ostream &operator<<(std::ostream &lhs, command const &rhs) {
102 return lhs << to_const_string(rhs);
103}
104
105constexpr command to_command(std::string_view name) noexcept
106{
107 if (name == "text_cursor_char_left") {
108 return command::text_cursor_char_left;
109 } else if (name == "text_cursor_char_right") {
110 return command::text_cursor_char_right;
111 } else if (name == "text_cursor_word_left") {
112 return command::text_cursor_word_left;
113 } else if (name == "text_cursor_word_right") {
114 return command::text_cursor_word_right;
115 } else if (name == "text_cursor_line_begin") {
116 return command::text_cursor_line_begin;
117 } else if (name == "text_cursor_line_end") {
118 return command::text_cursor_line_end;
119 } else if (name == "text_select_char_left") {
120 return command::text_select_char_left;
121 } else if (name == "text_select_char_right") {
122 return command::text_select_char_right;
123 } else if (name == "text_select_word") {
124 return command::text_select_word;
125 } else if (name == "text_select_word_left") {
126 return command::text_select_word_left;
127 } else if (name == "text_select_word_right") {
128 return command::text_select_word_right;
129 } else if (name == "text_select_line_begin") {
130 return command::text_select_line_begin;
131 } else if (name == "text_select_line_end") {
132 return command::text_select_line_end;
133 } else if (name == "text_select_document") {
134 return command::text_select_document;
135 } else if (name == "text_mode_insert") {
136 return command::text_mode_insert;
137 } else if (name == "text_delete_char_prev") {
138 return command::text_delete_char_prev;
139 } else if (name == "text_delete_char_next") {
140 return command::text_delete_char_next;
141 } else if (name == "text_edit_paste") {
142 return command::text_edit_paste;
143 } else if (name == "text_edit_copy") {
144 return command::text_edit_copy;
145 } else if (name == "text_edit_cut") {
146 return command::text_edit_cut;
147 } else if (name == "text_undo") {
148 return command::text_undo;
149 } else if (name == "text_redo") {
150 return command::text_redo;
151 } else if (name == "gui_keyboard_enter") {
152 return command::gui_keyboard_enter;
153 } else if (name == "gui_keyboard_exit") {
154 return command::gui_keyboard_exit;
155 } else if (name == "gui_mouse_enter") {
156 return command::gui_mouse_enter;
157 } else if (name == "gui_mouse_exit") {
158 return command::gui_mouse_exit;
159 } else if (name == "gui_widget_next") {
160 return command::gui_widget_next;
161 } else if (name == "gui_widget_prev") {
162 return command::gui_widget_prev;
163 } else if (name == "gui_menu_next") {
164 return command::gui_menu_next;
165 } else if (name == "gui_menu_prev") {
166 return command::gui_menu_prev;
167 } else if (name == "gui_toolbar_next") {
168 return command::gui_toolbar_next;
169 } else if (name == "gui_toolbar_prev") {
170 return command::gui_toolbar_prev;
171 } else if (name == "gui_activate") {
172 return command::gui_activate;
173 } else if (name == "gui_enter") {
174 return command::gui_enter;
175 } else if (name == "gui_escape") {
176 return command::gui_escape;
177 } else {
178 return command::unknown;
179 }
180}
181
182}
T to_string(T... args)