Skip to content

Pointer

Overview

The Pointer API provides a single interface for handling both mouse and touch inputs to maximize cross-platform compatibility.

API

pointer

Handles mouse and touch events simultaneously for easy cross-platform functionality.

pub fn pointer() -> Pointer
Pointer
pub struct Pointer {
    /// The x position of the mouse cursor or most recent touch event
    pub x: i32,
    /// The y position of the mouse cursor or most recent touch event
    pub y: i32,
    /// The state of the left mouse button or touch
    state: Button,
}

Usage

Using the pointer

let p = pointer();
 
// get the current mouse/touch position
let position_x = p.x;
let position_y = p.y;
 
if p.just_pressed() {
    // handle mouse click or touch event
}