#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct ClickEvent {
pub x: i16,
pub y: i16,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum PointerButton {
#[default]
Left,
Right,
Middle,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum PointerKind {
#[default]
Touch = 0,
Mouse = 1,
Pen = 2,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum CursorShape {
#[default]
Default = 0,
Pointer = 1,
Text = 2,
Grab = 3,
Grabbing = 4,
NotAllowed = 5,
Progress = 6,
Move = 7,
Crosshair = 8,
ResizeNS = 9,
ResizeEW = 10,
ResizeNWSE = 11,
ResizeNESW = 12,
}
impl CursorShape {
#[inline(always)]
pub const fn as_css_str(self) -> &'static str {
match self {
Self::Default => "default",
Self::Pointer => "pointer",
Self::Text => "text",
Self::Grab => "grab",
Self::Grabbing => "grabbing",
Self::NotAllowed => "not-allowed",
Self::Progress => "progress",
Self::Move => "move",
Self::Crosshair => "crosshair",
Self::ResizeNS => "ns-resize",
Self::ResizeEW => "ew-resize",
Self::ResizeNWSE => "nwse-resize",
Self::ResizeNESW => "nesw-resize",
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum SwipeDir {
Left,
Right,
Up,
Down,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct DragEvent {
pub x: i16,
pub y: i16,
pub local_x: i16,
pub local_y: i16,
pub width: i16,
pub height: i16,
pub delta_x: i16,
pub delta_y: i16,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct WheelEvent {
pub x: i16,
pub y: i16,
pub local_x: i16,
pub local_y: i16,
pub width: i16,
pub height: i16,
pub delta_x: i16,
pub delta_y: i16,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct PinchEvent {
pub x: i16,
pub y: i16,
pub local_x: i16,
pub local_y: i16,
pub width: i16,
pub height: i16,
pub delta_scale_x1000: i16,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum KeyCode {
Tab,
BackTab,
Up,
Down,
Left,
Right,
Enter,
Space,
Escape,
Backspace,
Delete,
Home,
End,
PageUp,
PageDown,
Char(char),
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Default)]
pub struct KeyModifiers(pub u8);
impl KeyModifiers {
pub const NONE: Self = Self(0);
pub const SHIFT: Self = Self(1 << 0);
pub const CTRL: Self = Self(1 << 1);
pub const ALT: Self = Self(1 << 2);
pub const LOGO: Self = Self(1 << 3);
#[inline(always)]
pub const fn is_empty(self) -> bool {
self.0 == 0
}
#[inline(always)]
pub const fn shift(self) -> bool {
(self.0 & Self::SHIFT.0) != 0
}
#[inline(always)]
pub const fn ctrl(self) -> bool {
(self.0 & Self::CTRL.0) != 0
}
#[inline(always)]
pub const fn alt(self) -> bool {
(self.0 & Self::ALT.0) != 0
}
#[inline(always)]
pub const fn logo(self) -> bool {
(self.0 & Self::LOGO.0) != 0
}
#[inline(always)]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline(always)]
pub const fn with(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline(always)]
pub const fn without(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
#[inline(always)]
pub const fn has_shortcut_modifier(self) -> bool {
(self.0 & (Self::LOGO.0 | Self::ALT.0 | Self::CTRL.0)) != 0
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct SafeAreaInsets {
pub top: i16,
pub right: i16,
pub bottom: i16,
pub left: i16,
}
impl SafeAreaInsets {
pub const ZERO: Self = Self {
top: 0,
right: 0,
bottom: 0,
left: 0,
};
#[inline(always)]
pub const fn new(top: i16, right: i16, bottom: i16, left: i16) -> Self {
Self {
top,
right,
bottom,
left,
}
}
#[inline(always)]
pub const fn phone_portrait() -> Self {
Self {
top: 44,
right: 0,
bottom: 34,
left: 0,
}
}
#[inline(always)]
pub const fn phone_landscape() -> Self {
Self {
top: 0,
right: 44,
bottom: 21,
left: 44,
}
}
#[inline(always)]
pub const fn android_portrait() -> Self {
Self {
top: 48,
right: 0,
bottom: 34,
left: 0,
}
}
#[inline(always)]
pub const fn android_landscape() -> Self {
Self {
top: 0,
right: 0,
bottom: 24,
left: 48,
}
}
#[inline(always)]
pub const fn ios_portrait() -> Self {
Self {
top: 59,
right: 0,
bottom: 34,
left: 0,
}
}
#[inline(always)]
pub const fn ios_landscape() -> Self {
Self {
top: 0,
right: 59,
bottom: 21,
left: 59,
}
}
#[inline(always)]
pub const fn harmony_portrait() -> Self {
Self {
top: 38,
right: 0,
bottom: 28,
left: 0,
}
}
#[inline(always)]
pub const fn harmony_landscape() -> Self {
Self {
top: 0,
right: 38,
bottom: 20,
left: 38,
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct ImePreedit {
pub buf: [u8; 64],
pub len: u8,
pub cursor_start: u8,
pub cursor_end: u8,
pub has_cursor: bool,
}
impl Default for ImePreedit {
#[inline(always)]
fn default() -> Self {
Self::empty()
}
}
impl ImePreedit {
#[inline(always)]
pub const fn empty() -> Self {
Self {
buf: [0; 64],
len: 0,
cursor_start: 0,
cursor_end: 0,
has_cursor: false,
}
}
pub fn from_str(text: &str, cursor: Option<(usize, usize)>) -> Self {
let mut out = Self::empty();
let bytes = text.as_bytes();
let mut copy_len = bytes.len().min(64);
while copy_len > 0 && !text.is_char_boundary(copy_len) {
copy_len -= 1;
}
out.buf[..copy_len].copy_from_slice(&bytes[..copy_len]);
out.len = copy_len as u8;
if let Some((s, e)) = cursor {
out.cursor_start = s.min(copy_len) as u8;
out.cursor_end = e.min(copy_len) as u8;
out.has_cursor = true;
}
out
}
#[inline]
pub fn as_str(&self) -> &str {
let n = (self.len as usize).min(64);
core::str::from_utf8(&self.buf[..n]).unwrap_or("")
}
#[inline(always)]
pub const fn is_empty(&self) -> bool {
self.len == 0
}
#[inline(always)]
pub const fn cursor(&self) -> Option<(usize, usize)> {
if self.has_cursor {
Some((self.cursor_start as usize, self.cursor_end as usize))
} else {
None
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum InputEvent {
PointerDown { x: i16, y: i16 },
PointerMove { x: i16, y: i16 },
PointerUp { x: i16, y: i16 },
PointerSecondaryDown { x: i16, y: i16 },
PointerSecondaryUp { x: i16, y: i16 },
PointerLeave,
PointerCancel,
PointerKindChanged(PointerKind),
Scroll {
x: i16,
y: i16,
delta_y: i16,
},
ScrollX {
x: i16,
y: i16,
delta_x: i16,
},
KeyDown(KeyCode),
KeyUp(KeyCode),
ModifiersChanged(KeyModifiers),
Backspace,
Delete,
TextCommit(char),
ImeEnabled,
ImeDisabled,
ImePreedit(ImePreedit),
NavigateBack,
SafeAreaChanged(SafeAreaInsets),
KeyboardInsetChanged(i16),
Pinch {
x: i16,
y: i16,
delta_scale_x1000: i16,
},
Rotate {
x: i16,
y: i16,
delta_deg10: i16,
},
ScrollPixel {
x: i16,
y: i16,
dx: i16,
dy: i16,
},
FileHovered { x: i16, y: i16 },
FileDropped { x: i16, y: i16 },
FileHoverCancelled,
SystemThemeChanged { dark: bool },
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum EventPhase {
Capture = 0,
#[default]
Target = 1,
Bubble = 2,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct DragPayload {
pub kind_tag: u32,
pub payload_id: u64,
pub source_id: u32,
}