pub struct Viewport { /* private fields */ }Expand description
Logical UI units mapped into a safe-area-aware pixel viewport.
Self::fit letterboxes a design canvas; Self::responsive keeps one
logical unit per host logical pixel and lets layout reflow.
Implementations§
Source§impl Viewport
impl Viewport
pub fn bounds(self) -> Rect
pub fn pixels(self) -> Rect
pub fn scale(self) -> f32
Sourcepub fn responsive(
screen: [f32; 2],
insets: [f32; 4],
) -> Result<Viewport, UiError>
pub fn responsive( screen: [f32; 2], insets: [f32; 4], ) -> Result<Viewport, UiError>
A HUD viewport with no font scaling or letterboxing. Insets are left, top,
right, bottom in host logical pixels; the host handles device pixel ratio.
Layout coordinates start at zero inside the safe area. Oversized insets
collapse their axis proportionally; zero-sized screens are valid and inert.
Negative/non-finite dimensions or insets return UiError::InvalidLayout.
use ferravex_play::ui::Viewport;
let hud = Viewport::responsive([320., 240.], [10., 20., 10., 0.])?;
assert_eq!(hud.bounds().size, [300., 220.]);
assert_eq!(hud.unproject([10., 20.]), Some([0., 0.]));
assert!(Viewport::responsive([0.; 2], [12.; 4])?.unproject([0.; 2]).is_none());Sourcepub fn fit(
screen: [f32; 2],
design: [f32; 2],
insets: [f32; 4],
) -> Result<Viewport, UiError>
pub fn fit( screen: [f32; 2], design: [f32; 2], insets: [f32; 4], ) -> Result<Viewport, UiError>
Insets are left, top, right, bottom in host logical pixels (DPR applied by host).
pub fn unproject(self, point: [f32; 2]) -> Option<[f32; 2]>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Viewport
impl RefUnwindSafe for Viewport
impl Send for Viewport
impl Sync for Viewport
impl Unpin for Viewport
impl UnwindSafe for Viewport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more