pub enum BoxFit {
Fill,
Contain,
Cover,
FitWidth,
FitHeight,
None,
ScaleDown,
}Expand description
How an image is fitted into its destination box — the same set of modes as the
CSS object-fit property.
Variants§
Fill
Stretches to fill the box; the aspect ratio is not preserved.
Contain
The largest scale that still fits inside the box (letterbox).
Cover
The smallest scale that covers the box (cropping).
FitWidth
Fits to the width; may overflow vertically.
FitHeight
Fits to the height; may overflow horizontally.
None
Natural size, centred — neither scaled up nor down.
ScaleDown
Like BoxFit::Contain, but never scaled up — only down.
Implementations§
Source§impl BoxFit
impl BoxFit
Sourcepub fn apply(self, src: Size, dst: Rect) -> (Rect, Rect)
pub fn apply(self, src: Size, dst: Rect) -> (Rect, Rect)
Computes the destination rectangle (inside or around dst) and the UV
rectangle (the sub-region of the texture, in 0..1) for drawing an image of
size src in this mode. dst is never cropped: letterboxing shrinks dst
and keeps full UV; cropping keeps dst full and shrinks the UV.
Sourcepub fn apply_aligned(
self,
src: Size,
dst: Rect,
align: Alignment,
) -> (Rect, Rect)
pub fn apply_aligned( self, src: Size, dst: Rect, align: Alignment, ) -> (Rect, Rect)
BoxFit::apply with a say in where the spare room goes: which part of the
box a letterboxed image sits in, and which part of the image a cropping one keeps.
Centre is the reference’s default and what apply uses. It matters as soon as an
image is not the shape of its box: a portrait cropped to a banner should usually
keep its top, not its middle.
Sourcepub fn scale(self, src: Size, dst: Size) -> (f32, f32)
pub fn scale(self, src: Size, dst: Size) -> (f32, f32)
The (sx, sy) scale factors that fit content of size src into a box of
size dst in this mode — the building block of FittedBox, where the
content, unlike a sampled image, is scaled and then centred. Fill
stretches per axis; every other mode is uniform, preserving the aspect
ratio. A degenerate src yields (1, 1).