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
impl TouchLayoutSettings
pub fn valid(self) -> bool
pub fn apply( self, c: Control, slot: usize, viewport: Vec2, ) -> Result<Control, InputError>
Sourcepub fn apply_in_safe_area(
self,
c: Control,
slot: usize,
viewport: Vec2,
safe_area: Rect,
) -> Result<Control, InputError>
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.));Sourcepub fn diagnose_layout(
controls: &[Control],
viewport: Vec2,
safe_area: Rect,
) -> Result<TouchLayoutDiagnostics, InputError>
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
impl Clone for TouchLayoutSettings
Source§fn clone(&self) -> TouchLayoutSettings
fn clone(&self) -> TouchLayoutSettings
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more