summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Cory Forsstrom <cforsstrom18@gmail.com>2020-04-23 15:34:55 -0700
committerLibravatar Cory Forsstrom <cforsstrom18@gmail.com>2020-05-26 16:56:34 -0700
commit0d8cefbf2d084053b92ded4785da8083486374ea (patch)
tree3c28573b56062a0a25ad13edf10464f08de1d9d0 /wgpu
parent5324eb10242a7dd33f5271dc6fc9eeb09eb2cb50 (diff)
downloadiced-0d8cefbf2d084053b92ded4785da8083486374ea.tar.gz
iced-0d8cefbf2d084053b92ded4785da8083486374ea.tar.bz2
iced-0d8cefbf2d084053b92ded4785da8083486374ea.zip
Add `ImagePane` widget
Diffstat (limited to '')
-rw-r--r--wgpu/src/renderer/widget.rs2
-rw-r--r--wgpu/src/renderer/widget/image_pane.rs36
-rw-r--r--wgpu/src/widget.rs8
-rw-r--r--wgpu/src/widget/image_pane.rs6
4 files changed, 52 insertions, 0 deletions
diff --git a/wgpu/src/renderer/widget.rs b/wgpu/src/renderer/widget.rs
index 37421fbe..6e1b7fe9 100644
--- a/wgpu/src/renderer/widget.rs
+++ b/wgpu/src/renderer/widget.rs
@@ -17,3 +17,5 @@ mod svg;
#[cfg(feature = "image")]
mod image;
+#[cfg(feature = "image")]
+mod image_pane;
diff --git a/wgpu/src/renderer/widget/image_pane.rs b/wgpu/src/renderer/widget/image_pane.rs
new file mode 100644
index 00000000..8b032250
--- /dev/null
+++ b/wgpu/src/renderer/widget/image_pane.rs
@@ -0,0 +1,36 @@
+use crate::{Primitive, Renderer};
+use iced_native::{image, image_pane, MouseCursor, Rectangle, Vector};
+
+impl image_pane::Renderer for Renderer {
+ fn draw(
+ &mut self,
+ state: &image_pane::State,
+ bounds: Rectangle,
+ image_bounds: Rectangle,
+ offset: (u32, u32),
+ handle: image::Handle,
+ is_mouse_over: bool,
+ ) -> Self::Output {
+ (
+ {
+ Primitive::Clip {
+ bounds,
+ offset: Vector::new(offset.0, offset.1),
+ content: Box::new(Primitive::Image {
+ handle,
+ bounds: image_bounds,
+ }),
+ }
+ },
+ {
+ if state.is_cursor_clicked() {
+ MouseCursor::Grabbing
+ } else if is_mouse_over {
+ MouseCursor::Grab
+ } else {
+ MouseCursor::OutOfBounds
+ }
+ },
+ )
+ }
+}
diff --git a/wgpu/src/widget.rs b/wgpu/src/widget.rs
index 32ccad17..a62a610d 100644
--- a/wgpu/src/widget.rs
+++ b/wgpu/src/widget.rs
@@ -47,3 +47,11 @@ pub mod canvas;
#[cfg(feature = "canvas")]
#[doc(no_inline)]
pub use canvas::Canvas;
+
+#[cfg(feature = "image")]
+#[doc(no_inline)]
+pub mod image_pane;
+
+#[cfg(feature = "image")]
+#[doc(no_inline)]
+pub use image_pane::ImagePane;
diff --git a/wgpu/src/widget/image_pane.rs b/wgpu/src/widget/image_pane.rs
new file mode 100644
index 00000000..aa30a8cc
--- /dev/null
+++ b/wgpu/src/widget/image_pane.rs
@@ -0,0 +1,6 @@
+//! Zoom and pan on an image.
+
+pub use iced_native::image_pane::State;
+
+/// A widget that can display an image with the ability to zoom in/out and pan.
+pub type ImagePane<'a> = iced_native::ImagePane<'a>;