Add ImagePane widget
This commit is contained in:
parent
5324eb1024
commit
0d8cefbf2d
7 changed files with 470 additions and 2 deletions
|
|
@ -17,3 +17,5 @@ mod svg;
|
|||
|
||||
#[cfg(feature = "image")]
|
||||
mod image;
|
||||
#[cfg(feature = "image")]
|
||||
mod image_pane;
|
||||
|
|
|
|||
36
wgpu/src/renderer/widget/image_pane.rs
Normal file
36
wgpu/src/renderer/widget/image_pane.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
6
wgpu/src/widget/image_pane.rs
Normal file
6
wgpu/src/widget/image_pane.rs
Normal file
|
|
@ -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>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue