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
impl TouchLayout
Sourcepub fn from_viewport(
viewport: Viewport,
slots: &[TouchSlot],
minimum: MinimumTouchSize,
) -> Result<TouchLayout, TouchGeometryError>
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.)));Sourcepub fn from_canvas(
canvas: Canvas2D,
slots: &[TouchSlot],
minimum: MinimumTouchSize,
) -> Result<TouchLayout, TouchGeometryError>
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 });Sourcepub fn controls(&self) -> &[Control]
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.
Sourcepub fn resolve(
&self,
settings: TouchLayoutSettings,
screen: [f32; 2],
) -> Result<TouchLayout, TouchGeometryError>
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
impl Clone for TouchLayout
Source§fn clone(&self) -> TouchLayout
fn clone(&self) -> TouchLayout
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more