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 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
Sets the border::Radius of the Image.
Currently, it will only be applied around the rectangular bounding box
of the Image.
Sourcepub fn alt(self, text: impl Into<String>) -> Self
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.
Sourcepub fn description(self, description: impl Into<String>) -> Self
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>
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,
_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.