Struct TouchLayoutSettings

Source
pub struct TouchLayoutSettings {
    pub mirrored: bool,
    pub scale: f32,
    pub opacity: f32,
    pub edits: [TouchEdit; 16],
}

Fields§

§mirrored: bool§scale: f32§opacity: f32§edits: [TouchEdit; 16]

Implementations§

Source§

impl TouchLayoutSettings

Source

pub fn valid(self) -> bool

Source

pub fn apply( self, c: Control, slot: usize, viewport: Vec2, ) -> Result<Control, InputError>

Source

pub fn apply_in_safe_area( self, c: Control, slot: usize, viewport: Vec2, safe_area: Rect, ) -> Result<Control, InputError>

Apply saved edits inside a checked safe rectangle in logical pixels.

c must be the authored control for viewport, before any saved edits or safe-area adaptation. Its center is mapped by center / viewport into safe_area; mirroring and normalized edit offsets are relative to that area. Buttons and sticks keep their logical-pixel size, scaled by the saved settings, with the same 44-pixel minimum and 8-pixel margin as customized Self::apply layouts. Oversized controls shrink to fit. Look regions scale with the safe area and fit without that margin; like apply, they ignore per-slot edits and size settings.

Always recompute from authored controls when resizing. Neither saved offsets nor authored controls are mutated, so clamping in a small area cannot accumulate drift after resizing back. Geometry never depends on opacity or edits to other slots. Unlike legacy apply, default settings also fit controls. Installing a changed layout in TouchSurface still releases existing captures; this method does not remap active fingers.

Returns InputError::InvalidTouch for invalid settings/slot/control, non-finite or out-of-range geometry, or a safe area outside the viewport. Each viewport dimension must be in 64..=1_000_000; each safe-area dimension must be at least 64. Resolved controls must also satisfy the existing touch geometry limits. Errors leave caller-owned state intact.

use ferravex_math::{Rect, Vec2};
use ferravex_play::input::touch::{Control, Output, Region, TouchLayoutSettings};
let mut settings = TouchLayoutSettings::default();
settings.edits[0].offset = Vec2::new(0.1, 0.);
let authored = Control {
    region: Region::Circle { center: Vec2::new(100., 100.), radius: 24. },
    output: Output::Button(0),
};
let viewport = Vec2::new(400., 200.);
let safe = Rect::new(20., 10., 360., 180.);
let resolved = settings.apply_in_safe_area(authored, 0, viewport, safe)?;
assert_eq!(resolved.region, Region::Circle {
    center: Vec2::new(146., 100.), radius: 24.,
});
assert!(TouchLayoutSettings::diagnose_layout(&[resolved], viewport, safe)?.is_clear());
assert_eq!(settings.edits[0].offset, Vec2::new(0.1, 0.));
Source

pub fn diagnose_layout( controls: &[Control], viewport: Vec2, safe_area: Rect, ) -> Result<TouchLayoutDiagnostics, InputError>

Check resolved controls against a safe area without applying settings.

Reports all out-of-bounds regions and every intersecting pair, including pairs outside the safe area. Shape tests distinguish circles from their bounding boxes and include tangencies, matching inclusive touch regions. Work is bounded by 16 controls / 120 pairs and allocates no heap storage. Invalid controls or safe geometry return InputError::InvalidTouch; more than MAX_TOUCH_CONTROLS returns InputError::TouchCapacity. Safe-area limits are those of Self::apply_in_safe_area.

use ferravex_math::{Rect, Vec2};
use ferravex_play::input::touch::{Control, Output, Region, TouchLayoutSettings};
let controls = [Control {
    region: Region::Circle { center: Vec2::splat(50.), radius: 24. },
    output: Output::Button(0),
}];
let report = TouchLayoutSettings::diagnose_layout(
    &controls, Vec2::splat(100.), Rect::new(0., 0., 100., 100.),
)?;
assert!(report.is_clear());

Trait Implementations§

Source§

impl Clone for TouchLayoutSettings

Source§

fn clone(&self) -> TouchLayoutSettings

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 TouchLayoutSettings

Source§

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

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

impl Default for TouchLayoutSettings

Source§

fn default() -> TouchLayoutSettings

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

impl PartialEq for TouchLayoutSettings

Source§

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

Source§

const SCHEMA: u64 = 5_068_894_080_315_115_569u64

Source§

const VERSION: u32 = 1u32

Source§

const MAX_BYTES: usize = 512usize

Source§

fn write(&self, d: &mut Document) -> Result<(), SaveError>

Source§

fn read(d: &Document) -> Result<TouchLayoutSettings, SaveError>

Source§

fn encode(&self, generation: u64) -> Result<Vec<u8>, SaveError>

Source§

fn decode(data: &[u8]) -> Result<(Self, u64), SaveError>

Source§

impl Copy for TouchLayoutSettings

Source§

impl StructuralPartialEq for TouchLayoutSettings

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.