[−][src]Struct druid::widget::Image
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]
pub fn event(
&mut self,
_ctx: &mut EventCtx<'_, '_>,
_event: &Event,
_data: &mut T,
_env: &Env
)
[src]
&mut self,
_ctx: &mut EventCtx<'_, '_>,
_event: &Event,
_data: &mut T,
_env: &Env
)
pub fn lifecycle(
&mut self,
_ctx: &mut LifeCycleCtx<'_, '_>,
_event: &LifeCycle,
_data: &T,
_env: &Env
)
[src]
&mut self,
_ctx: &mut LifeCycleCtx<'_, '_>,
_event: &LifeCycle,
_data: &T,
_env: &Env
)
pub fn update(
&mut self,
_ctx: &mut UpdateCtx<'_, '_>,
_old_data: &T,
_data: &T,
_env: &Env
)
[src]
&mut self,
_ctx: &mut UpdateCtx<'_, '_>,
_old_data: &T,
_data: &T,
_env: &Env
)
pub fn layout(
&mut self,
_layout_ctx: &mut LayoutCtx<'_, '_>,
bc: &BoxConstraints,
_data: &T,
_env: &Env
) -> Size
[src]
&mut self,
_layout_ctx: &mut LayoutCtx<'_, '_>,
bc: &BoxConstraints,
_data: &T,
_env: &Env
) -> Size
pub fn paint(&mut self, ctx: &mut PaintCtx<'_, '_, '_>, _data: &T, _env: &Env)
[src]
Auto Trait Implementations
impl RefUnwindSafe for Image
[src]
impl !Send for Image
[src]
impl !Sync for Image
[src]
impl Unpin for Image
[src]
impl UnwindSafe for Image
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
pub fn round_into(self) -> U
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,