Skip to main content

Image

Struct Image 

Source
pub struct Image<Handle = Handle> { /* private fields */ }
Available on crate feature image only.
Expand description

A frame that displays an image while keeping aspect ratio.

§Example

use iced::widget::image;

enum Message {
    // ...
}

fn view(state: &State) -> Element<'_, Message> {
    image("ferris.png").into()
}

Implementations§

Source§

impl<Handle> Image<Handle>

Source

pub fn new(handle: impl Into<Handle>) -> Self

Creates a new Image with the given path.

Source

pub fn width(self, width: impl Into<Length>) -> Self

Sets the width of the Image boundaries.

Source

pub fn height(self, height: impl Into<Length>) -> Self

Sets the height of the Image boundaries.

Source

pub fn expand(self, expand: bool) -> Self

Sets whether the Image should try to fill as much space available as possible while keeping aspect ratio and without allocating extra space in any axis with a Length::Shrink sizing strategy.

This is similar to using Length::Fill for both the width and the height, but without the downside of blank space.

Source

pub fn content_fit(self, content_fit: ContentFit) -> Self

Sets the ContentFit of the Image.

Defaults to ContentFit::Contain

Source

pub fn filter_method(self, filter_method: FilterMethod) -> Self

Sets the FilterMethod of the Image.

Source

pub fn rotation(self, rotation: impl Into<Rotation>) -> Self

Applies the given Rotation to the Image.

Source

pub fn opacity(self, opacity: impl Into<f32>) -> Self

Sets the opacity of the Image.

It should be in the [0.0, 1.0] range—0.0 meaning completely transparent, and 1.0 meaning completely opaque.

Source

pub fn scale(self, scale: impl Into<f32>) -> Self

Sets the scale of the Image.

The region of the Image drawn will be scaled from the center by the given scale factor. This can be useful to create certain effects and animations, like smooth zoom in / out.

Source

pub fn crop(self, region: Rectangle<u32>) -> Self

Crops the Image to the given region described by the Rectangle in absolute coordinates.

Cropping is done before applying any transformation or ContentFit. In practice, this means that cropping an Image with this method should produce the same result as cropping it externally (e.g. with an image editor) and creating a new Handle for the cropped version.

However, this method is much more efficient; since it just leverages scissoring during rendering and no image cropping actually takes place. Instead, it reuses the existing image allocations and should be as efficient as not cropping at all!

The region coordinates will be clamped to the image dimensions, if necessary.

Source

pub fn border_radius(self, border_radius: impl Into<Radius>) -> Self

Sets the border::Radius of the Image.

Currently, it will only be applied around the rectangular bounding box of the Image.

Source

pub fn alt(self, text: impl Into<String>) -> Self

Sets the alt text of the Image.

This is the accessible name announced by screen readers. It should be a short phrase describing the image content.

Source

pub fn description(self, description: impl Into<String>) -> Self

Sets an extended description of the Image.

This supplements the alt text with additional context for assistive technology, when the alt text alone is not sufficient.

Trait Implementations§

Source§

impl<'a, Message, Theme, Renderer, Handle> From<Image<Handle>> for Element<'a, Message, Theme, Renderer>
where Renderer: Renderer<Handle = Handle>, Handle: Clone + 'a,

Source§

fn from(image: Image<Handle>) -> Element<'a, Message, Theme, Renderer>

Converts to this type from the input type.
Source§

impl<Message, Theme, Renderer, Handle> Widget<Message, Theme, Renderer> for Image<Handle>
where Renderer: Renderer<Handle = Handle>, Handle: Clone,

Source§

fn size(&self) -> Size<Length>

Returns the Size of the Widget in lengths.
Source§

fn layout( &mut self, _tree: &mut Tree, renderer: &Renderer, limits: &Limits, ) -> Node

Returns the layout::Node of the Widget. Read more
Source§

fn draw( &self, _tree: &Tree, renderer: &mut Renderer, _theme: &Theme, _style: &Style, layout: Layout<'_>, _cursor: Cursor, _viewport: &Rectangle, )

Draws the Widget using the associated Renderer.
Source§

fn operate( &mut self, _tree: &mut Tree, layout: Layout<'_>, _renderer: &Renderer, operation: &mut dyn Operation, )

Applies an Operation to the Widget.
Source§

fn size_hint(&self) -> Size<Length>

Returns a Size hint for laying out the Widget. Read more
Source§

fn tag(&self) -> Tag

Returns the Tag of the Widget.
Source§

fn state(&self) -> State

Returns the State of the Widget.
Source§

fn children(&self) -> Vec<Tree>

Returns the state Tree of the children of the Widget.
Source§

fn diff(&self, tree: &mut Tree)

Reconciles the Widget with the provided Tree.
Source§

fn update( &mut self, _tree: &mut Tree, _event: &Event, _layout: Layout<'_>, _cursor: Cursor, _renderer: &Renderer, _shell: &mut Shell<'_, Message>, _viewport: &Rectangle, )

Processes a runtime Event. Read more
Source§

fn mouse_interaction( &self, _tree: &Tree, _layout: Layout<'_>, _cursor: Cursor, _viewport: &Rectangle, _renderer: &Renderer, ) -> Interaction

Returns the current mouse::Interaction of the Widget. Read more
Source§

fn overlay<'a>( &'a mut self, _tree: &'a mut Tree, _layout: Layout<'a>, _renderer: &Renderer, _viewport: &Rectangle, _translation: Vector, ) -> Option<Element<'a, Message, Theme, Renderer>>

Returns the overlay of the Widget, if there is any.

Auto Trait Implementations§

§

impl<Handle> Freeze for Image<Handle>
where Handle: Freeze,

§

impl<Handle> RefUnwindSafe for Image<Handle>
where Handle: RefUnwindSafe,

§

impl<Handle> Send for Image<Handle>
where Handle: Send,

§

impl<Handle> Sync for Image<Handle>
where Handle: Sync,

§

impl<Handle> Unpin for Image<Handle>
where Handle: Unpin,

§

impl<Handle> UnsafeUnpin for Image<Handle>
where Handle: UnsafeUnpin,

§

impl<Handle> UnwindSafe for Image<Handle>
where Handle: UnwindSafe,

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> 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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

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

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,