Merge remote-tracking branch 'tarkah/image-pane' into image-pane

This commit is contained in:
Héctor Ramón Jiménez 2020-12-18 10:15:30 +01:00
commit 0b73e5fbfa
5 changed files with 560 additions and 2 deletions

View file

@ -1,11 +1,14 @@
//! Display images in your user interface.
pub mod viewer;
use crate::backend::{self, Backend};
use crate::{Primitive, Renderer};
use iced_native::image;
use iced_native::mouse;
use iced_native::Layout;
pub use iced_native::image::{Handle, Image};
pub use iced_native::image::{Handle, Image, Viewer};
impl<B> image::Renderer for Renderer<B>
where

View file

@ -0,0 +1,51 @@
//! Zoom and pan on an image.
use crate::backend::{self, Backend};
use crate::{Primitive, Renderer};
use iced_native::{
image::{self, viewer},
mouse, Rectangle, Vector,
};
impl<B> viewer::Renderer for Renderer<B>
where
B: Backend + backend::Image,
{
fn draw(
&mut self,
state: &viewer::State,
bounds: Rectangle,
image_bounds: Rectangle,
translation: Vector,
handle: image::Handle,
is_mouse_over: bool,
) -> Self::Output {
(
{
Primitive::Clip {
bounds,
content: Box::new(Primitive::Translate {
translation,
content: Box::new(Primitive::Image {
handle,
bounds: image_bounds,
}),
}),
offset: Vector::new(0, 0),
}
},
{
if state.is_cursor_clicked() {
mouse::Interaction::Grabbing
} else if is_mouse_over
&& (image_bounds.width > bounds.width
|| image_bounds.height > bounds.height)
{
mouse::Interaction::Grab
} else {
mouse::Interaction::Idle
}
},
)
}
}