pub struct Image { /* private fields */ }
Expand description
A widget that renders a bitmap Image.
Contains data about how to fill the given space and interpolate pixels. Configuration options are provided via the builder pattern.
Note: when scaling a bitmap image, such as supporting multiple
screen sizes and resolutions, interpolation can lead to blurry
or pixelated images and so is not recommended for things like icons.
Instead consider using SVG files and enabling the svg
feature with cargo
.
(See also: ImageBuf
, FillStrat
, InterpolationMode
)
Example
Create an image widget and configure it using builder methods
use druid::{
widget::{Image, FillStrat},
piet::{ImageBuf, InterpolationMode},
};
let image_data = ImageBuf::empty();
let image_widget = Image::new(image_data)
// set the fill strategy
.fill_mode(FillStrat::Fill)
// set the interpolation mode
.interpolation_mode(InterpolationMode::Bilinear);
Create an image widget and configure it using setters
use druid::{
widget::{Image, FillStrat},
piet::{ImageBuf, InterpolationMode},
};
let image_data = ImageBuf::empty();
let mut image_widget = Image::new(image_data);
// set the fill strategy
image_widget.set_fill_mode(FillStrat::FitWidth);
// set the interpolation mode
image_widget.set_interpolation_mode(InterpolationMode::Bilinear);
Implementations§
source§impl Image
impl Image
sourcepub fn new(image_data: ImageBuf) -> Self
pub fn new(image_data: ImageBuf) -> Self
Create an image drawing widget from an image buffer.
By default, the Image will scale to fit its box constraints (FillStrat::Fill
)
and will be scaled bilinearly (InterpolationMode::Bilinear
)
The underlying ImageBuf
uses Arc
for buffer data, making it cheap to clone.
sourcepub fn fill_mode(self, mode: FillStrat) -> Self
pub fn fill_mode(self, mode: FillStrat) -> Self
Builder-style method for specifying the fill strategy.
sourcepub fn set_fill_mode(&mut self, newfil: FillStrat)
pub fn set_fill_mode(&mut self, newfil: FillStrat)
Modify the widget’s fill strategy.
sourcepub fn interpolation_mode(self, interpolation: InterpolationMode) -> Self
pub fn interpolation_mode(self, interpolation: InterpolationMode) -> Self
Builder-style method for specifying the interpolation strategy.
sourcepub fn set_interpolation_mode(&mut self, interpolation: InterpolationMode)
pub fn set_interpolation_mode(&mut self, interpolation: InterpolationMode)
Modify the widget’s interpolation mode.
sourcepub fn clip_area(self, clip_area: Option<Rect>) -> Self
pub fn clip_area(self, clip_area: Option<Rect>) -> Self
Builder-style method for setting the area of the image that will be displayed.
If None
, then the whole image will be displayed.
sourcepub fn set_clip_area(&mut self, clip_area: Option<Rect>)
pub fn set_clip_area(&mut self, clip_area: Option<Rect>)
Set the area of the image that will be displayed.
If None
, then the whole image will be displayed.
sourcepub fn set_image_data(&mut self, image_data: ImageBuf)
pub fn set_image_data(&mut self, image_data: ImageBuf)
Set new ImageBuf
.