1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2025 the UI Events Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Cross-platform input event types modeled after W3C UI Events.
//!
//! This crate provides small, portable data types for working with pointer
//! (mouse, touch, pen) and keyboard input in a platform-agnostic way.
//! It aims to closely follow W3C terminology while remaining practical for native
//! application development.
//!
//! ## What you get:
//!
//! - Pointer events: button down/up, move, enter/leave, scroll, gestures
//! - Rich pointer state: position, pressure, tilt, contact size, modifiers
//! - Keyboard types re-exported from [`keyboard-types`]
//! - A stable vocabulary you can adapt from windowing backends
//!
//! This crate is intentionally focused on data structures — it does not open
//! windows or read events.
//! For integrations, see the adapter crates:
//!
//! - [`ui-events-winit`]: Convert between `winit` and `ui-events`.
//! - [`ui-events-web`]: Convert between Web (`web-sys`) DOM events and `ui-events`.
//!
//! ## Coordinate system and units
//!
//! - Positions are in physical pixels (`dpi::PhysicalPosition<f64>`), with the
//! Y axis increasing downward.
//! - Use [`PointerState::logical_position`](pointer::PointerState::logical_position)
//! to obtain logical coordinates using a scale factor.
//! - Scroll deltas are expressed via [`ScrollDelta`]; see its docs for details
//! on page/line/pixel semantics.
//!
//! ## Primary pointer
//!
//! Some interactions need a notion of a “primary” pointer (e.g. left mouse button, first touch).
//! The reserved id [`PointerId::PRIMARY`](pointer::PointerId::PRIMARY) marks this.
//! Helper methods like [`PointerEvent::is_primary_pointer`](pointer::PointerEvent::is_primary_pointer)
//! and [`PointerInfo::is_primary_pointer`](pointer::PointerInfo::is_primary_pointer) are provided for convenience.
//!
//! ## Feature flags
//!
//! - `std` (default): Use the Rust standard library.
//! - `kurbo`: Add convenience methods for converting positions to `kurbo::Point`.
//!
//! ## Examples
//!
//! Basic matching on pointer events:
//!
//! ```
//! use ui_events::pointer::{PointerEvent, PointerButton, PointerButtonEvent, PointerInfo, PointerState, PointerType};
//! use ui_events::ScrollDelta;
//! use keyboard_types::Modifiers;
//! use dpi::{PhysicalPosition, PhysicalSize};
//!
//! fn handle_event(ev: PointerEvent) {
//! match ev {
//! PointerEvent::Down(PointerButtonEvent { button, state, .. }) => {
//! if button == Some(PointerButton::Primary) {
//! // Start a drag, for example
//! let pos = state.position;
//! let _ = (pos.x, pos.y);
//! }
//! }
//! PointerEvent::Move(upd) => {
//! let logical = upd.current.logical_position();
//! let _ = (logical.x, logical.y);
//! }
//! PointerEvent::Scroll(s) => {
//! match s.delta {
//! ScrollDelta::PageDelta(x, y) => { let _ = (x, y); }
//! ScrollDelta::LineDelta(x, y) => { let _ = (x, y); }
//! ScrollDelta::PixelDelta(p) => { let _ = (p.x, p.y); }
//! }
//! }
//! _ => {}
//! }
//! }
//!
//! // Construct a minimal primary-pointer Down event
//! let ev = PointerEvent::Down(PointerButtonEvent{
//! button: Some(PointerButton::Primary),
//! pointer: PointerInfo{
//! pointer_id: Some(ui_events::pointer::PointerId::PRIMARY),
//! persistent_device_id: None,
//! pointer_type: PointerType::Mouse,
//! },
//! state: PointerState{
//! time: 0,
//! position: PhysicalPosition { x: 10.0, y: 20.0 },
//! buttons: Default::default(),
//! modifiers: Modifiers::empty(),
//! count: 1,
//! contact_geometry: PhysicalSize { width: 1.0, height: 1.0 },
//! orientation: Default::default(),
//! pressure: 0.5,
//! tangential_pressure: 0.0,
//! scale_factor: 2.0,
//! },
//! });
//! handle_event(ev);
//! ```
//!
//! ## See also
//!
//! - [`ui-events-winit`]
//! - [`ui-events-web`]
//! - [`keyboard-types`]
//!
//! [`keyboard-types`]: https://docs.rs/keyboard-types/
//! [`ui-events-winit`]: https://docs.rs/ui-events-winit/
//! [`ui-events-web`]: https://docs.rs/ui-events-web/
//! [`winit`]: https://docs.rs/winit/
// LINEBENDER LINT SET - lib.rs - v3
// See https://linebender.org/wiki/canonical-lints/
// These lints shouldn't apply to examples or tests.
// These lints shouldn't apply to examples.
// Targeting e.g. 32-bit means structs containing usize can give false positives for 64-bit.
// END LINEBENDER LINT SET
pub use ScrollDelta;