Skip to main content

BoxFit

Enum BoxFit 

Source
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

Source

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.

Source

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.

Source

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).

Trait Implementations§

Source§

impl Clone for BoxFit

Source§

fn clone(&self) -> BoxFit

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BoxFit

Source§

impl Debug for BoxFit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for BoxFit

Source§

fn default() -> BoxFit

Returns the “default value” for a type. Read more
Source§

impl Eq for BoxFit

Source§

impl PartialEq for BoxFit

Source§

fn eq(&self, other: &BoxFit) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BoxFit

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.