use crate::{ConstInit, EventTimestamp, Key, KeyMods, KeyState};
#[doc = crate::_tags!(event interaction)]
#[doc = crate::_doc_location!("ui/event")]
#[doc = "See also [`EventKeyFfi`]."]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct EventKey {
pub timestamp: Option<EventTimestamp>,
pub semantic: Key,
pub physical: Key,
pub mods: KeyMods,
pub state: KeyState,
}
impl ConstInit for EventKey {
const INIT: Self = Self {
semantic: Key::INIT,
physical: Key::INIT,
state: KeyState::INIT,
mods: KeyMods::INIT,
timestamp: None,
};
}
#[cfg(ffi··)]
pub use ffi::*;
#[cfg(ffi··)]
#[rustfmt::skip]
#[cfg_attr(nightly_doc, doc(cfg(ffi··)))]
mod ffi {
use super::*;
use crate::{ConstInit, KeyFfi, f32bits, is};
#[doc = crate::_tags!(event interaction ffi)]
#[doc = crate::_doc_location!("ui/event")]
#[repr(C)]
#[allow(missing_docs)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct EventKeyFfi {
#[doc = crate::_tags!(ffi)]
pub timestamp: f32bits,
#[doc = crate::_tags!(ffi)]
pub semantic: KeyFfi,
#[doc = crate::_tags!(ffi)]
pub physical: KeyFfi,
pub state: KeyState,
pub mods: KeyMods,
}
impl EventKey {
pub const fn to_ffi(&self) -> EventKeyFfi {
EventKeyFfi {
semantic: self.semantic.to_ffi(),
physical: self.physical.to_ffi(),
state: self.state,
mods: self.mods,
timestamp: is![let Some(t) = self.timestamp, t.get_non_niche(), f32bits::INIT],
}
}
pub const fn from_ffi(from: &EventKeyFfi) -> EventKey {
EventKey {
semantic: Key::from_ffi(from.semantic),
physical: Key::from_ffi(from.physical),
state: from.state,
mods: from.mods,
timestamp: Some(EventTimestamp::from_non_niche(from.timestamp)),
}
}
}
impl From<&EventKey> for EventKeyFfi { fn from(e: &EventKey) -> Self { EventKey::to_ffi(e) } }
impl From<&EventKeyFfi> for EventKey { fn from(e: &EventKeyFfi) -> Self { Self::from_ffi(e) } }
impl From<EventKey> for EventKeyFfi { fn from(e: EventKey) -> Self { EventKey::to_ffi(&e) } }
impl From<EventKeyFfi> for EventKey { fn from(e: EventKeyFfi) -> Self { Self::from_ffi(&e) } }
}