Rename and add to iced image module

This commit is contained in:
Cory Forsstrom 2020-05-15 09:46:22 -07:00
parent 6bf459e068
commit 431171f975
No known key found for this signature in database
GPG key ID: 64D6B5851FFCAC9E
7 changed files with 58 additions and 56 deletions

View file

@ -0,0 +1,39 @@
use crate::{Primitive, Renderer};
use iced_native::{image, image_viewer, mouse, Rectangle, Vector};
impl image_viewer::Renderer for Renderer {
fn draw(
&mut self,
state: &image_viewer::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() {
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
}
},
)
}
}