Struct TouchSurface

Source
pub struct TouchSurface { /* private fields */ }

Implementations§

Source§

impl TouchSurface

Source

pub fn controls(&self) -> &[Control]

Identical layouts preserve captures. A changed/resized layout releases all old output codes before installing the new one, without reallocating.

Source

pub fn set_layout( &mut self, controls: &[Control], map: &mut ActionMap, ) -> Result<(), InputError>

Source

pub fn handle( &mut self, event: Event, map: &mut ActionMap, ) -> Result<(), InputError>

Source

pub fn handle_scaled( &mut self, event: Event, map: &mut ActionMap, look_scale: Vec2, ) -> Result<(), InputError>

Apply a host’s per-pixel sensitivity before motion reaches bound actions.

Source

pub fn gesture_profile(&self) -> Option<GestureProfile>

Current opt-in profile; None by default. See Self::set_gesture_profile.

Source

pub fn set_gesture_profile( &mut self, profile: Option<GestureProfile>, map: &mut ActionMap, ) -> Result<(), GestureError>

Validate before mutation. A different profile (including enable/disable) clears all captures, releases their held outputs and resets the supplied time watermark. An identical profile preserves captures/time. Unrelated queued input edges and accumulated motion are not consumed or erased. Invalid profiles preserve all state, even with active captures.

use ferravex_play::input::{ActionMap, touch::{TouchSurface, GestureProfile}};
let mut map = ActionMap::default();
let mut touch = TouchSurface::default();
assert_eq!(touch.gesture_profile(), None);
touch.set_gesture_profile(Some(GestureProfile::default()), &mut map)?;
assert!(touch.gesture_profile().is_some());
touch.set_gesture_profile(None, &mut map)?;
assert_eq!(touch.gesture_profile(), None);
Source

pub fn handle_timed( &mut self, event: Event, seconds: f64, map: &mut ActionMap, ) -> Result<Option<GestureObservation>, GestureError>

Handle immediate controls and return an optional gesture using supplied seconds, without consuming any action edges. Equivalent to Self::handle_timed_scaled with unit look sensitivity.

use ferravex_math::{Rect, Vec2};
use ferravex_play::input::{ActionMap, Binding, InputCode, touch::*};
let mut map = ActionMap::default();
let jump = map.try_action(vec![Binding::digital(InputCode::Touch(0))]).unwrap();
let mut touch = TouchSurface::default();
touch.set_layout(&[Control { region: Region::Rect(Rect::new(0., 0., 100., 100.)),
    output: Output::Button(0) }], &mut map)?;
touch.set_gesture_profile(Some(GestureProfile::default()), &mut map)?;
let event = |phase| Event { id: 7, position: Vec2::splat(20.), phase };
assert!(touch.handle_timed(event(Phase::Start), 10.0, &mut map)?.is_none());
let observed = touch.handle_timed(event(Phase::End), 10.125, &mut map)?.unwrap();
assert_eq!((observed.kind, observed.elapsed_seconds), (GestureKind::Tap, 0.125));
// No actual simulation tick yet: both immediate button edges remain.
assert!(map.peek(jump).pressed && map.peek(jump).released);
let tick = map.consume_tick(jump); // Only inside an actual executed update.
assert!(tick.pressed && tick.released);
assert!(!map.consume_tick(jump).pressed);
Source

pub fn handle_timed_scaled( &mut self, event: Event, seconds: f64, map: &mut ActionMap, look_scale: Vec2, ) -> Result<Option<GestureObservation>, GestureError>

Supplied-time observation with the same capture ownership, layout priority and immediate outputs as Self::handle_scaled. Look scaling affects only existing TouchDelta outputs; recognition uses unscaled logical pixels. See Self::handle_timed for an executable example.

Supply finite nonnegative seconds in one caller-owned monotonic domain (prefer seconds since session start). Equal timestamps are allowed. Time must not decrease across any successfully accepted timed events on this surface, including uncaptured IDs. No wall clock is inferred. Caller f64 precision determines time resolution. Clear, changed layout or changed profile forgets this watermark, so focus loss needs no timestamp.

Error precedence: disabled profile, invalid seconds, decreasing seconds, then legacy position/scale/capture-capacity validation. Every error leaves map, captures, recognition and watermark unchanged. Uncaptured events have no observation. There are at most MAX_TOUCHES captures; a repeated Start replaces that ID’s old capture/gesture (or drops it if outside the layout), even at capacity. Cancel always drops recognition without a tap/swipe. End uses its own position, even without a Move; legacy control release still ignores End motion. Repeated End cannot deliver the observation again.

A capture is observed only if its Start used this timed path. Successfully accepted untimed events drop recognition for their affected capture while preserving legacy output behavior; later timed events cannot revive it. Mixing timed and untimed pointers is allowed. Recognition storage is inline, with no queue/backpressure: each call returns at most one observation that the caller must handle immediately or retain in its own bounded storage.

Source

pub fn clear(&mut self, map: &mut ActionMap)

Release captures and discard recognition/time history, retaining the configured profile. Valid for focus loss with no supplied timestamp. Does not consume queued action edges or reset unrelated input sources.

Source

pub fn active(&self) -> usize

Source

pub fn stick(&self, x: u8, y: u8) -> Option<(Vec2, Vec2)>

Trait Implementations§

Source§

impl Default for TouchSurface

Source§

fn default() -> TouchSurface

Returns the “default value” for a type. Read more

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> 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, 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.