diff options
Diffstat (limited to 'graphics/src/widget/image/viewer.rs')
-rw-r--r-- | graphics/src/widget/image/viewer.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/graphics/src/widget/image/viewer.rs b/graphics/src/widget/image/viewer.rs new file mode 100644 index 00000000..b6217ff7 --- /dev/null +++ b/graphics/src/widget/image/viewer.rs @@ -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 + } + }, + ) + } +} |