Struct TouchLayout

Source
pub struct TouchLayout { /* private fields */ }
Expand description

Fixed-capacity projected controls; construction/resolution allocate nothing. Rebuild from authored slots on resize; do not feed resolved geometry back in. Empty layouts release existing captures when installed through PlayerInput.

Implementations§

Source§

impl TouchLayout

Source

pub fn from_viewport( viewport: Viewport, slots: &[TouchSlot], minimum: MinimumTouchSize, ) -> Result<TouchLayout, TouchGeometryError>

Project viewport-local shapes, including TouchSlot::rect UI rectangles. Bounds are not a clip: shapes extending outside the viewport stay intact. A viewport with either displayed extent below one logical pixel suspends the entire layout, after validating slot order and authored geometry.

use ferravex_render::{input::{touch::Output, touch_layout::*}, ui::{UiRect, Viewport}};
let v = Viewport::fit([800., 600.], [400., 200.], [0.; 4]).unwrap();
let slots = [TouchSlot::rect(0, UiRect { min: [10., 20.], size: [30., 40.] }, Output::Button(7))];
let layout = TouchLayout::from_viewport(v, &slots, MinimumTouchSize::Require(44.))?;
assert_eq!(layout.controls()[0].region, ferravex_render::input::touch::Region::Rect(
    ferravex_render::Rect::new(20., 140., 60., 80.)));
Source

pub fn from_canvas( canvas: Canvas2D, slots: &[TouchSlot], minimum: MinimumTouchSize, ) -> Result<TouchLayout, TouchGeometryError>

Project canvas-world shapes using the same affine arithmetic as drawing. No crop is applied, preserving existing broad/background touch regions. Manually authored canvas fields are checked; zero/subpixel screen or displayed-world extents suspend input instead of leaving stale targets.

use ferravex_render::{vec2, canvas::Canvas2D,
    input::{touch::{Control, Output, Region}, touch_layout::*}};
let canvas = Canvas2D::try_fit(vec2(400., 200.), vec2(800., 600.))?.unwrap();
let slots = [TouchSlot { slot: 0, control: Some(Control {
    region: Region::Circle { center: vec2(20., 30.), radius: 22. },
    output: Output::Stick { x: 0, y: 1, radius: 16., floating: false },
}) }];
let layout = TouchLayout::from_canvas(canvas, &slots, MinimumTouchSize::Preserve)?;
assert_eq!(layout.controls()[0].region,
    Region::Circle { center: canvas.project(vec2(20., 30.)), radius: 44. });
assert_eq!(layout.controls()[0].output,
    Output::Stick { x: 0, y: 1, radius: 32., floating: false });
Source

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

Visible prefix, in unchanged authored slot order. Used for both drawing and installation; boundaries retain existing inclusive touch hit tests. Overlapping/shared edges resolve to the earliest slot, as in TouchSurface.

Source

pub fn resolve( &self, settings: TouchLayoutSettings, screen: [f32; 2], ) -> Result<TouchLayout, TouchGeometryError>

Resolve the exact legacy PlayerInput customization for drawing. Supply current full-screen logical dimensions, not the safe-area size. Like PlayerInput, each dimension is floored at 64 before settings.apply. Safe offsets are already projected; apply_in_safe_area here would apply them twice. This method never mutates settings, channels or saved slots. The minimum is checked again after edits; errors preserve the authored value. Never install this result into PlayerInput a second time.

Trait Implementations§

Source§

impl Clone for TouchLayout

Source§

fn clone(&self) -> TouchLayout

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 TouchLayout

Source§

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

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

impl PartialEq for TouchLayout

Source§

fn eq(&self, other: &TouchLayout) -> 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 TouchLayout

Source§

impl StructuralPartialEq for TouchLayout

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