diff options
author | crupest <crupest@outlook.com> | 2020-10-28 16:58:56 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-28 16:58:56 +0800 |
commit | 2df47ffbfff02fb6b64d19e404adc41a93677afe (patch) | |
tree | e15a566c95b68b6266bdcab14bba64be729ab300 /include/cru/ui/ShortcutHub.hpp | |
parent | fde24556042b76863bdec34dcc213cb7298f68f9 (diff) | |
download | cru-2df47ffbfff02fb6b64d19e404adc41a93677afe.tar.gz cru-2df47ffbfff02fb6b64d19e404adc41a93677afe.tar.bz2 cru-2df47ffbfff02fb6b64d19e404adc41a93677afe.zip |
...
Diffstat (limited to 'include/cru/ui/ShortcutHub.hpp')
-rw-r--r-- | include/cru/ui/ShortcutHub.hpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/include/cru/ui/ShortcutHub.hpp b/include/cru/ui/ShortcutHub.hpp index a1dfcb7d..5382f63e 100644 --- a/include/cru/ui/ShortcutHub.hpp +++ b/include/cru/ui/ShortcutHub.hpp @@ -12,6 +12,7 @@ #include <optional> #include <string> #include <string_view> +#include <type_traits> #include <unordered_map> #include <vector> @@ -71,6 +72,15 @@ struct hash<cru::ui::ShortcutKeyBind> { } // namespace std namespace cru::ui { +struct Shortcut { + // Just for debug. + std::u16string name; + ShortcutKeyBind key_bind; + // Return true if it consumes the shortcut. Or return false if it does not + // handle the shortcut. + std::function<bool()> handler; +}; + struct ShortcutInfo { int id; std::u16string name; @@ -87,11 +97,13 @@ class ShortcutHub : public Object { ~ShortcutHub() override = default; - // Handler return true if it consumes the shortcut. Or return false if it does - // not handle the shortcut. Name is just for debug. Return an id used for - // unregistering. int RegisterShortcut(std::u16string name, ShortcutKeyBind bind, - std::function<bool()> handler); + std::function<bool()> handler) { + return RegisterShortcut({std::move(name), bind, std::move(handler)}); + } + + // Return an id used for unregistering. + int RegisterShortcut(Shortcut shortcut); void UnregisterShortcut(int id); |