pub struct Image<Handle = Handle> { /* private fields */ }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>
impl<Handle> Image<Handle>
Sourcepub fn height(self, height: impl Into<Length>) -> Self
pub fn height(self, height: impl Into<Length>) -> Self
Sets the height of the Image boundaries.
Sourcepub fn expand(self, expand: bool) -> Self
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.
Sourcepub fn content_fit(self, content_fit: ContentFit) -> Self
pub fn content_fit(self, content_fit: ContentFit) -> Self
Sets the [ContentFit] of the Image.
Defaults to [ContentFit::Contain]
Sourcepub fn filter_method(self, filter_method: FilterMethod) -> Self
pub fn filter_method(self, filter_method: FilterMethod) -> Self
Sets the FilterMethod of the Image.
Sourcepub fn rotation(self, rotation: impl Into<Rotation>) -> Self
pub fn rotation(self, rotation: impl Into<Rotation>) -> Self
Applies the given [Rotation] to the Image.
Sourcepub fn opacity(self, opacity: impl Into<f32>) -> Self
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.
Sourcepub fn crop(self, region: Rectangle<u32>) -> Self
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.
Sourcepub fn border_radius(self, border_radius: impl Into<Radius>) -> Self
pub fn border_radius(self, border_radius: impl Into<Radius>) -> Self
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,
impl<'a, Message, Theme, Renderer, Handle> From<Image<Handle>> for Element<'a, Message, Theme, Renderer>where
Renderer: Renderer<Handle = Handle>,
Handle: Clone + 'a,
Source§impl<Message, Theme, Renderer, Handle> Widget<Message, Theme, Renderer> for Image<Handle>where
Renderer: Renderer<Handle = Handle>,
Handle: Clone,
impl<Message, Theme, Renderer, Handle> Widget<Message, Theme, Renderer> for Image<Handle>where
Renderer: Renderer<Handle = Handle>,
Handle: Clone,
Source§fn draw(
&self,
_tree: &Tree,
renderer: &mut Renderer,
_theme: &Theme,
_style: &Style,
layout: Layout<'_>,
_cursor: Cursor,
_viewport: &Rectangle,
)
fn draw( &self, _tree: &Tree, renderer: &mut Renderer, _theme: &Theme, _style: &Style, layout: Layout<'_>, _cursor: Cursor, _viewport: &Rectangle, )
Widget] using the associated Renderer.§fn operate(
&mut self,
_tree: &mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
_operation: &mut dyn Operation,
)
fn operate( &mut self, _tree: &mut Tree, _layout: Layout<'_>, _renderer: &Renderer, _operation: &mut dyn Operation, )
Operation] to the [Widget].§fn update(
&mut self,
_tree: &mut Tree,
_event: &Event,
_layout: Layout<'_>,
_cursor: Cursor,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
)
fn update( &mut self, _tree: &mut Tree, _event: &Event, _layout: Layout<'_>, _cursor: Cursor, _renderer: &Renderer, _clipboard: &mut dyn Clipboard, _shell: &mut Shell<'_, Message>, _viewport: &Rectangle, )
§fn mouse_interaction(
&self,
_tree: &Tree,
_layout: Layout<'_>,
_cursor: Cursor,
_viewport: &Rectangle,
_renderer: &Renderer,
) -> Interaction
fn mouse_interaction( &self, _tree: &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<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