7#include "../utility/module.hpp"
8#include "../strings.hpp"
11namespace hi::inline
v1 {
26[[nodiscard]]
constexpr keyboard_modifiers operator|(keyboard_modifiers
const& lhs, keyboard_modifiers
const& rhs)
noexcept
28 return static_cast<keyboard_modifiers
>(to_underlying(lhs) | to_underlying(rhs));
31[[nodiscard]]
constexpr keyboard_modifiers operator&(keyboard_modifiers
const& lhs, keyboard_modifiers
const& rhs)
noexcept
36constexpr keyboard_modifiers& operator|=(keyboard_modifiers& lhs, keyboard_modifiers
const& rhs)
noexcept
38 return lhs = lhs | rhs;
41[[nodiscard]]
constexpr bool to_bool(keyboard_modifiers
const& rhs)
noexcept
43 return to_bool(to_underlying(rhs));
46bool operator>=(keyboard_modifiers
const& lhs, keyboard_modifiers
const& rhs) =
delete;
54 throw parse_error(
"Empty keyboard modifier");
58 hilet s_lower = to_lower((s.back() ==
'+') ? s.substr(0, ssize(s) - 1) : s);
60 if (s_lower ==
"shift") {
61 return keyboard_modifiers::shift;
62 }
else if (s_lower ==
"control" || s_lower ==
"ctrl" || s_lower ==
"cntr") {
63 return keyboard_modifiers::control;
64 }
else if (s_lower ==
"alt" || s_lower ==
"option" || s_lower ==
"meta") {
65 return keyboard_modifiers::alt;
66 }
else if (s_lower ==
"windows" || s_lower ==
"win" || s_lower ==
"command" || s_lower ==
"cmd" || s_lower ==
"super") {
67 return keyboard_modifiers::super;
69 throw parse_error(std::format(
"Unknown keyboard modifier '{}'", s));
77 if (to_bool(modifiers & keyboard_modifiers::shift)) {
80 if (to_bool(modifiers & keyboard_modifiers::control)) {
83 if (to_bool(modifiers & keyboard_modifiers::alt)) {
86 if (to_bool(modifiers & keyboard_modifiers::super)) {
108template<
typename CharT>
109struct std::formatter<
hi::keyboard_modifiers, CharT> : std::formatter<std::string_view, CharT> {
110 auto format(hi::keyboard_modifiers
const& t,
auto& fc)
112 return std::formatter<std::string_view, CharT>::format(
hi::to_string(t), fc);
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
constexpr std::string to_string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:215
DOXYGEN BUG.
Definition algorithm.hpp:13
keyboard_modifiers
Key modification keys pressed at the same time as another key.
Definition keyboard_modifiers.hpp:18
@ 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:51
geometry/margins.hpp
Definition cache.hpp:11