[][src]Struct druid::widget::Image

pub struct Image { /* fields omitted */ }

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

impl Image[src]

pub fn new(image_data: ImageBuf) -> Self[src]

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.

pub fn fill_mode(self, mode: FillStrat) -> Self[src]

A builder-style method for specifying the fill strategy.

pub fn set_fill_mode(&mut self, newfil: FillStrat)[src]

Modify the widget's fill strategy.

pub fn interpolation_mode(self, interpolation: InterpolationMode) -> Self[src]

A builder-style method for specifying the interpolation strategy.

pub fn set_interpolation_mode(&mut self, interpolation: InterpolationMode)[src]

Modify the widget's interpolation mode.

pub fn clip_area(self, clip_area: Option<Rect>) -> Self[src]

Set the area of the image that will be displayed.

If None, then the whole image will be displayed.

pub fn set_clip_area(&mut self, clip_area: Option<Rect>)[src]

Set the area of the image that will be displayed.

If None, then the whole image will be displayed.

pub fn set_image_data(&mut self, image_data: ImageBuf)[src]

Set new ImageBuf.

Trait Implementations

impl<T: Data> Widget<T> for Image[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> RoundFrom<T> for T

impl<T, U> RoundInto<U> for T where
    U: RoundFrom<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.