7#include "imgui/imgui.h"
13constexpr std::pair<ImGuiKey, const char*>
kKeyNames[] = {
14 {ImGuiKey_Tab,
"Tab"},
15 {ImGuiKey_LeftArrow,
"Left"},
16 {ImGuiKey_RightArrow,
"Right"},
17 {ImGuiKey_UpArrow,
"Up"},
18 {ImGuiKey_DownArrow,
"Down"},
19 {ImGuiKey_PageUp,
"PageUp"},
20 {ImGuiKey_PageDown,
"PageDown"},
21 {ImGuiKey_Home,
"Home"},
22 {ImGuiKey_End,
"End"},
23 {ImGuiKey_Insert,
"Insert"},
24 {ImGuiKey_Delete,
"Delete"},
25 {ImGuiKey_Backspace,
"Backspace"},
26 {ImGuiKey_Space,
"Space"},
27 {ImGuiKey_Enter,
"Enter"},
28 {ImGuiKey_Escape,
"Escape"},
29 {ImGuiMod_Ctrl,
"Ctrl"},
30 {ImGuiMod_Shift,
"Shift"},
31 {ImGuiMod_Alt,
"Alt"},
32 {ImGuiMod_Super,
"Super"},
68 {ImGuiKey_F10,
"F10"},
69 {ImGuiKey_F11,
"F11"},
70 {ImGuiKey_F12,
"F12"},
71 {ImGuiKey_F13,
"F13"},
72 {ImGuiKey_F14,
"F14"},
73 {ImGuiKey_F15,
"F15"},
78 if (pair.first == key) {
88 for (
size_t i = keys.size(); i > 0; --i) {
89 shortcut += GetKeyName(keys[i - 1]);
103 std::vector<ImGuiKey> shortcuts;
107 size_t end = shortcut.find(
kCtrlKey);
108 if (end != std::string::npos) {
109 shortcuts.push_back(ImGuiMod_Ctrl);
113 end = shortcut.find(
kAltKey, start);
114 if (end != std::string::npos) {
115 shortcuts.push_back(ImGuiMod_Alt);
120 if (end != std::string::npos) {
121 shortcuts.push_back(ImGuiMod_Shift);
126 if (end != std::string::npos) {
127 shortcuts.push_back(ImGuiMod_Super);
132 while (start < shortcut.size()) {
142 for (
const auto& shortcut : shortcut_manager.
GetShortcuts()) {
143 bool keys_pressed =
true;
145 for (
const auto& key : shortcut.second.keys) {
146 if (key == ImGuiMod_Ctrl) {
147 keys_pressed &= ImGui::GetIO().KeyCtrl;
148 }
else if (key == ImGuiMod_Alt) {
149 keys_pressed &= ImGui::GetIO().KeyAlt;
150 }
else if (key == ImGuiMod_Shift) {
151 keys_pressed &= ImGui::GetIO().KeyShift;
152 }
else if (key == ImGuiMod_Super) {
153 keys_pressed &= ImGui::GetIO().KeySuper;
155 keys_pressed &= ImGui::IsKeyDown(key);
162 shortcut.second.callback();
auto GetShortcuts() const
constexpr std::pair< ImGuiKey, const char * > kKeyNames[]
constexpr const char * GetKeyName(ImGuiKey key)
Editors are the view controllers for the application.
constexpr std::string kCtrlKey
constexpr std::string kShiftKey
std::vector< ImGuiKey > ParseShortcut(const std::string &shortcut)
std::string PrintShortcut(const std::vector< ImGuiKey > &keys)
constexpr std::string kSuperKey
void ExecuteShortcuts(const ShortcutManager &shortcut_manager)
constexpr std::string kAltKey
ImGuiKey MapKeyToImGuiKey(char key)
Main namespace for the application.