| Crates.io | ui-events |
| lib.rs | ui-events |
| version | 0.3.0 |
| created_at | 2025-05-01 17:31:13.957132+00 |
| updated_at | 2026-01-18 06:19:12.368334+00 |
| description | A crate for working with UI events and input types. |
| homepage | |
| repository | https://github.com/endoli/ui-events |
| max_upload_size | |
| id | 1656575 |
| size | 108,763 |
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.
keyboard-typesThis 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.dpi::PhysicalPosition<f64>), with the
Y axis increasing downward.PointerState::logical_position
to obtain logical coordinates using a scale factor.ScrollDelta]; see its docs for details
on page/line/pixel semantics.Some interactions need a notion of a “primary” pointer (e.g. left mouse button, first touch).
The reserved id PointerId::PRIMARY marks this.
Helper methods like PointerEvent::is_primary_pointer
and PointerInfo::is_primary_pointer are provided for convenience.
std (default): Use the Rust standard library.kurbo: Add convenience methods for converting positions to kurbo::Point.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);
This version of UI Events has been verified to compile with Rust 1.85 and later.
Future versions of UI Events might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases.
As time has passed, some of UI Events' dependencies could have released versions with a higher Rust requirement. If you encounter a compilation issue due to a dependency and don't want to upgrade your Rust toolchain, then you could downgrade the dependency.
# Use the problematic dependency's name and version
cargo update -p package_name --precise 0.1.1
Discussion of UI Events development happens in the Linebender Zulip, specifically the #general channel. All public content can be read without logging in.
Licensed under either of
at your option.
Contributions are welcome by pull request. The Rust code of conduct applies. Please feel free to add your name to the AUTHORS file in any substantive pull request.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.