pub struct Image<Handle = Handle> { /* private fields */ }
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>
impl<Handle> Image<Handle>
Sourcepub fn new(handle: impl Into<Handle>) -> Image<Handle>
pub fn new(handle: impl Into<Handle>) -> Image<Handle>
Creates a new Image
with the given path.
Sourcepub fn width(self, width: impl Into<Length>) -> Image<Handle>
pub fn width(self, width: impl Into<Length>) -> Image<Handle>
Sets the width of the Image
boundaries.
Sourcepub fn height(self, height: impl Into<Length>) -> Image<Handle>
pub fn height(self, height: impl Into<Length>) -> Image<Handle>
Sets the height of the Image
boundaries.
Sourcepub fn expand(self, expand: bool) -> Image<Handle>
pub fn expand(self, expand: bool) -> Image<Handle>
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.
Sourcepub fn content_fit(self, content_fit: ContentFit) -> Image<Handle>
pub fn content_fit(self, content_fit: ContentFit) -> Image<Handle>
Sets the ContentFit
of the Image
.
Defaults to ContentFit::Contain
Sourcepub fn filter_method(self, filter_method: FilterMethod) -> Image<Handle>
pub fn filter_method(self, filter_method: FilterMethod) -> Image<Handle>
Sets the FilterMethod
of the Image
.
Sourcepub fn opacity(self, opacity: impl Into<f32>) -> Image<Handle>
pub fn opacity(self, opacity: impl Into<f32>) -> Image<Handle>
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.
Sourcepub fn crop(self, region: Rectangle<u32>) -> Image<Handle>
pub fn crop(self, region: Rectangle<u32>) -> Image<Handle>
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.
Trait Implementations§
Source§impl<'a, Message, Theme, Renderer, Handle> From<Image<Handle>> for Element<'a, Message, Theme, Renderer>
impl<'a, Message, Theme, Renderer, Handle> From<Image<Handle>> for Element<'a, Message, Theme, Renderer>
Source§impl<Message, Theme, Renderer, Handle> Widget<Message, Theme, Renderer> for Image<Handle>
impl<Message, Theme, Renderer, Handle> Widget<Message, Theme, Renderer> for Image<Handle>
Source§fn draw(
&self,
_state: &Tree,
renderer: &mut Renderer,
_theme: &Theme,
_style: &Style,
layout: Layout<'_>,
_cursor: Cursor,
viewport: &Rectangle,
)
fn draw( &self, _state: &Tree, renderer: &mut Renderer, _theme: &Theme, _style: &Style, layout: Layout<'_>, _cursor: Cursor, viewport: &Rectangle, )
Widget
using the associated Renderer
.§fn operate(
&mut self,
_state: &mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
_operation: &mut dyn Operation,
)
fn operate( &mut self, _state: &mut Tree, _layout: Layout<'_>, _renderer: &Renderer, _operation: &mut dyn Operation, )
§fn update(
&mut self,
_state: &mut Tree,
_event: &Event,
_layout: Layout<'_>,
_cursor: Cursor,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
)
fn update( &mut self, _state: &mut Tree, _event: &Event, _layout: Layout<'_>, _cursor: Cursor, _renderer: &Renderer, _clipboard: &mut dyn Clipboard, _shell: &mut Shell<'_, Message>, _viewport: &Rectangle, )
§fn mouse_interaction(
&self,
_state: &Tree,
_layout: Layout<'_>,
_cursor: Cursor,
_viewport: &Rectangle,
_renderer: &Renderer,
) -> Interaction
fn mouse_interaction( &self, _state: &Tree, _layout: Layout<'_>, _cursor: Cursor, _viewport: &Rectangle, _renderer: &Renderer, ) -> Interaction
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> UnwindSafe for Image<Handle>where
Handle: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application
.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more