pub enum ObjectFit {
Fill,
Contain,
Cover,
ContainInteger,
}Expand description
How a sized piece of content (an image or SVG) is scaled into its layout box, mirroring CSS object-fit.
Variants§
Fill
Stretch to fill the box exactly, ignoring the intrinsic aspect ratio (may distort).
Contain
Scale uniformly to fit inside the box, centered, leaving letterbox gaps (no clipping).
Cover
Scale uniformly to cover the box, centered; the overflow must be clipped to the box.
ContainInteger
Like Contain but by a whole number, centered.
The variant CSS has no name for, and the only one a pixel-art image can use: at a fractional scale some source pixels land on four screen pixels and their neighbours on five, so the grid the artist drew stops being a grid. Flooring the scale keeps every pixel the same size and spends the remainder on a wider letterbox.
Falls back to Contain when the content does not fit even once, since there is no whole number
below one to floor to.