use EnumBitFlags::EnumBitFlags;
#[EnumBitFlags(bits = 8)]
pub enum KeyModifier {
Alt = 0x01,
Ctrl = 0x02,
Shift = 0x04,
}
static KEY_NAME: [&str; 8] = [
"",
"Alt+",
"Ctrl+",
"Ctrl+Alt+",
"Shift+",
"Alt+Shift+",
"Ctrl+Shift+",
"Ctrl+Alt+Shift+",
];
impl KeyModifier {
pub fn name(&self) -> &'static str {
if self.value < 8 {
return KEY_NAME[self.value as usize];
}
""
}
pub(crate) fn name_from_index(index: usize) -> &'static str {
if index < 8 { KEY_NAME[index] } else { "" }
}
}
impl From<u8> for KeyModifier {
fn from(value: u8) -> Self {
if value < 8 {
let mut result = KeyModifier::None;
if (value & 1) != 0 {
result |= KeyModifier::Alt;
}
if (value & 2) != 0 {
result |= KeyModifier::Ctrl;
}
if (value & 4) != 0 {
result |= KeyModifier::Shift;
}
return result;
}
KeyModifier::None
}
}