Skip to main content

InputEvent

Enum InputEvent 

Source
pub enum InputEvent {
    Pan {
        dx: f64,
        dy: f64,
        x: Option<f64>,
        y: Option<f64>,
    },
    Zoom {
        factor: f64,
        x: Option<f64>,
        y: Option<f64>,
    },
    Rotate {
        delta_yaw: f64,
        delta_pitch: f64,
    },
    Resize {
        width: u32,
        height: u32,
    },
    Touch(TouchContact),
}
Expand description

An input event that can be dispatched to the engine.

All spatial values are in logical pixels unless otherwise noted. Rotation values are in radians.

§Examples

use rustial_engine::InputEvent;

// Drag the map 10 px right and 5 px down.
let pan = InputEvent::pan(10.0, 5.0);

// Zoom in by 10 %.
let zoom = InputEvent::zoom_in(1.1);

// Tilt the camera 5 degrees (? 0.087 rad).
let rotate = InputEvent::rotate(0.0, 0.087);

// Viewport resized.
let resize = InputEvent::resize(1920, 1080);

Variants§

§

Pan

Pan the camera by a screen-space delta.

Positive dx moves the viewport to the right (map moves left). Positive dy moves the viewport down (map moves up).

Fields

§dx: f64

Horizontal pixel delta (positive = right).

§dy: f64

Vertical pixel delta (positive = down).

§x: Option<f64>

Cursor’s X position in logical pixels (where the drag started or currently is).

§y: Option<f64>

Cursor’s Y position in logical pixels.

§

Zoom

Zoom by a multiplicative factor.

  • factor > 1.0 zooms in (closer to the ground).
  • 0 < factor < 1.0 zooms out.
  • factor <= 0, NaN, or +/-Inf are silently ignored by the CameraController.

Fields

§factor: f64

Multiplicative zoom factor.

§x: Option<f64>

Cursor X position in logical pixels used as the zoom anchor.

§y: Option<f64>

Cursor Y position in logical pixels used as the zoom anchor.

§

Rotate

Rotate the camera by delta yaw and delta pitch.

  • delta_yaw rotates the bearing (positive = clockwise when viewed from above).
  • delta_pitch tilts the camera (positive = toward horizon).

Fields

§delta_yaw: f64

Change in yaw (bearing) in radians.

§delta_pitch: f64

Change in pitch (tilt) in radians.

§

Resize

Notify the engine of a viewport resize.

The engine uses logical pixel dimensions (not physical) so that zoom-level calculations match the standard slippy-map convention.

Fields

§width: u32

New viewport width in logical pixels.

§height: u32

New viewport height in logical pixels.

§

Touch(TouchContact)

A raw touch contact event.

The host application emits one Touch per finger per phase change. The engine’s GestureRecognizer accumulates these into high-level Pan / Zoom / Rotate events.

Implementations§

Source§

impl InputEvent

Source

pub fn pan(dx: f64, dy: f64) -> Self

Create a Pan event.

Source

pub fn pan_at(dx: f64, dy: f64, x: f64, y: f64) -> Self

Create a Pan event at a specific cursor location.

Source

pub fn zoom_in(factor: f64) -> Self

Create a Zoom event that zooms in.

factor should be > 1.0. Values ? 0 will be ignored by the controller.

Source

pub fn zoom_at(factor: f64, x: f64, y: f64) -> Self

Create a Zoom event around a specific cursor location.

Source

pub fn zoom_out(factor: f64) -> Self

Create a Zoom event that zooms out.

factor should be > 1.0; the reciprocal is stored so the controller sees a value in (0, 1).

Source

pub fn rotate(delta_yaw: f64, delta_pitch: f64) -> Self

Create a Rotate event.

Source

pub fn resize(width: u32, height: u32) -> Self

Create a Resize event.

Source

pub fn touch(id: u64, phase: TouchPhase, x: f64, y: f64) -> Self

Create a Touch event.

Source§

impl InputEvent

Source

pub fn is_pan(&self) -> bool

Returns true if this is a Pan event.

Source

pub fn is_zoom(&self) -> bool

Returns true if this is a Zoom event.

Source

pub fn is_rotate(&self) -> bool

Returns true if this is a Rotate event.

Source

pub fn is_resize(&self) -> bool

Returns true if this is a Resize event.

Source

pub fn is_touch(&self) -> bool

Returns true if this is a Touch event.

Trait Implementations§

Source§

impl Clone for InputEvent

Source§

fn clone(&self) -> InputEvent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InputEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for InputEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for InputEvent

Source§

fn eq(&self, other: &InputEvent) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for InputEvent

Source§

impl StructuralPartialEq for InputEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.