pub struct AspectRatio { /* private fields */ }Expand description
A width-to-height ratio, exact.
Stored as an integer fraction rather than an f64 because 16:9 is not
representable in binary floating point, and a window that must stay
aspect-locked across thousands of resize events accumulates that error into
a visible drift. Comparisons and the fit math below stay in integers where
they can.
Implementations§
Source§impl AspectRatio
impl AspectRatio
Sourcepub const WIDESCREEN: Self
pub const WIDESCREEN: Self
16:9.
Sourcepub const fn new(width: u32, height: u32) -> Self
pub const fn new(width: u32, height: u32) -> Self
A ratio of width : height.
§Panics
If either term is zero. A degenerate aspect ratio has no correct behaviour and silently substituting one hides the caller’s bug.
Sourcepub const fn denominator(self) -> u32
pub const fn denominator(self) -> u32
The height term.
Sourcepub fn fit(self, bounds: PhysicalSize) -> PhysicalSize
pub fn fit(self, bounds: PhysicalSize) -> PhysicalSize
The largest size with this aspect ratio that fits inside bounds.
This is the letterbox computation, and it lives here because
the windowing rules in docs/notes/backends.md make in-renderer letterboxing the
universal fallback: Wayland has no aspect hint at all, and a tiling
window manager can force any size on any backend, so every consumer that
aspect-locks needs this math and none of them should write it twice.
Returns a size of at most bounds in both axes, and at least 1×1.