use crate::ConstInit;
#[cfg(all(feature = "js", not(windows)))]
use crate::{WebEventKind, is};
#[doc = crate::_tags!(interaction)]
#[doc = crate::_doc_location!("ui/event")]
#[repr(u8)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum KeyState {
#[default]
Press,
Release,
Repeat,
}
impl ConstInit for KeyState {
const INIT: Self = Self::Press;
}
#[cfg(all(feature = "js", not(windows)))]
#[cfg_attr(nightly_doc, doc(cfg(feature = "js")))]
impl KeyState {
#[must_use]
pub const fn from_js(from: WebEventKind, repeat: bool) -> Option<KeyState> {
match from {
WebEventKind::KeyDown => Some(is![repeat, KeyState::Repeat, KeyState::Press]),
WebEventKind::KeyUp => Some(KeyState::Release),
_ => None,
}
}
#[must_use]
pub const fn to_js(self) -> WebEventKind {
match self {
KeyState::Press => WebEventKind::KeyDown,
KeyState::Release => WebEventKind::KeyUp,
KeyState::Repeat => WebEventKind::KeyDown,
}
}
}