logo
pub enum ContentFit {
    Contain,
    Cover,
    Fill,
    None,
    ScaleDown,
}
Expand description

The strategy used to fit the contents of a widget to its bounding box.

Each variant of this enum is a strategy that can be applied for resolving differences in aspect ratio and size between the image being displayed and the space its being displayed in.

For an interactive demonstration of these properties as they are implemented in CSS, see Mozilla’s docs, or run the tour example

Variants

Contain

Scale as big as it can be without needing to crop or hide parts.

The image will be scaled (preserving aspect ratio) so that it just fits within the window. This won’t distort the image or crop/hide any edges, but if the image doesn’t fit perfectly, there may be whitespace on the top/bottom or left/right.

This is a great fit for when you need to display an image without losing any part of it, particularly when the image itself is the focus of the screen.

Cover

Scale the image to cover all of the bounding box, cropping if needed.

This doesn’t distort the image, and it ensures that the widget’s area is completely covered, but it might crop off a bit of the edges of the widget, particularly when there is a big difference between the aspect ratio of the widget and the aspect ratio of the image.

This is best for when you’re using an image as a background, or to fill space, and any details of the image around the edge aren’t too important.

Fill

Distort the image so the widget is 100% covered without cropping.

This stretches the image to fit the widget, without any whitespace or cropping. However, because of the stretch, the image may look distorted or elongated, particularly when there’s a mismatch of aspect ratios.

None

Don’t resize or scale the image at all.

This will not apply any transformations to the provided image, but also means that unless you do the math yourself, the widget’s area will not be completely covered, or the image might be cropped.

This is best for when you’ve sized the image yourself.

ScaleDown

Scale the image down if it’s too big for the space, but never scale it up.

This works much like Contain, except that if the image would have been scaled up, it keeps its original resolution to avoid the bluring that accompanies upscaling images.

Implementations

Attempt to apply the given fit for a content size within some bounds.

The returned value is the recommended scaled size of the content.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Convert the source color to the destination color using the specified method Read more

Convert the source color to the destination color using the bradford method by default Read more

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Convert into T with values clamped to the color defined bounds Read more

Convert into T. The resulting color might be invalid in its color space Read more

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more