7#include "../utility/utility.hpp"
8#include "../algorithm/algorithm.hpp"
9#include "../macros.hpp"
20hi_export
namespace hi::inline
v1 {
35[[nodiscard]]
constexpr keyboard_modifiers operator|(keyboard_modifiers
const& lhs, keyboard_modifiers
const& rhs)
noexcept
37 return static_cast<keyboard_modifiers
>(std::to_underlying(lhs) | std::to_underlying(rhs));
40[[nodiscard]]
constexpr keyboard_modifiers operator&(keyboard_modifiers
const& lhs, keyboard_modifiers
const& rhs)
noexcept
42 return static_cast<keyboard_modifiers>(std::to_underlying(lhs) & std::to_underlying(rhs));
45constexpr keyboard_modifiers& operator|=(keyboard_modifiers& lhs, keyboard_modifiers
const& rhs)
noexcept
47 return lhs = lhs | rhs;
50[[nodiscard]]
constexpr bool to_bool(keyboard_modifiers
const& rhs)
noexcept
52 return to_bool(std::to_underlying(rhs));
55bool operator>=(keyboard_modifiers
const& lhs, keyboard_modifiers
const& rhs) =
delete;
63 throw parse_error(
"Empty keyboard modifier");
67 auto const s_lower = to_lower((s.back() ==
'+') ? s.substr(0, ssize(s) - 1) : s);
69 if (s_lower ==
"shift") {
70 return keyboard_modifiers::shift;
71 }
else if (s_lower ==
"control" || s_lower ==
"ctrl" || s_lower ==
"cntr") {
72 return keyboard_modifiers::control;
73 }
else if (s_lower ==
"alt" || s_lower ==
"option" || s_lower ==
"meta") {
74 return keyboard_modifiers::alt;
75 }
else if (s_lower ==
"windows" || s_lower ==
"win" || s_lower ==
"command" || s_lower ==
"cmd" || s_lower ==
"super") {
76 return keyboard_modifiers::super;
78 throw parse_error(std::format(
"Unknown keyboard modifier '{}'", s));
82inline std::string to_string(keyboard_modifiers modifiers)
86 if (to_bool(modifiers & keyboard_modifiers::shift)) {
89 if (to_bool(modifiers & keyboard_modifiers::control)) {
92 if (to_bool(modifiers & keyboard_modifiers::alt)) {
95 if (to_bool(modifiers & keyboard_modifiers::super)) {
119struct std::formatter<
hi::keyboard_modifiers, char> : std::formatter<std::string_view, char> {
120 auto format(hi::keyboard_modifiers
const& t,
auto& fc)
const
122 return std::formatter<std::string_view, char>::format(hi::to_string(t), fc);
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
keyboard_modifiers
Key modification keys pressed at the same time as another key.
Definition keyboard_modifiers.hpp:27
@ super
The windows-key, key-key or super-key is being held.
@ shift
The shift key is being held.
@ alt
The alt-key, option-key or meta-key is being held.
@ control
The control key is being held.
keyboard_modifiers to_keyboard_modifiers(std::string_view s)
Parse a key-binding modifier name.
Definition keyboard_modifiers.hpp:60