Rebase to master and update for api changes

This commit is contained in:
Cory Forsstrom 2020-05-14 11:54:05 -07:00
parent 7f7e803448
commit 6bf459e068
No known key found for this signature in database
GPG Key ID: 64D6B5851FFCAC9E
2 changed files with 19 additions and 42 deletions

View File

@ -1,9 +1,7 @@
//! Zoom and pan on an image. //! Zoom and pan on an image.
use crate::{ use crate::{
image, image, layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length,
input::{self, mouse}, Point, Rectangle, Size, Widget,
layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Rectangle, Size, Widget,
}; };
use std::{f32, hash::Hash, u32}; use std::{f32, hash::Hash, u32};
@ -154,21 +152,8 @@ where
match event { match event {
Event::Mouse(mouse::Event::WheelScrolled { delta }) => { Event::Mouse(mouse::Event::WheelScrolled { delta }) => {
match delta { match delta {
mouse::ScrollDelta::Lines { y, .. } => { mouse::ScrollDelta::Lines { y, .. }
// TODO: Configurable step and limits | mouse::ScrollDelta::Pixels { y, .. } => {
if y > 0.0 {
self.state.scale = Some(
(self.state.scale.unwrap_or(1.0) + 0.25)
.min(10.0),
);
} else {
self.state.scale = Some(
(self.state.scale.unwrap_or(1.0) - 0.25)
.max(0.25),
);
}
}
mouse::ScrollDelta::Pixels { y, .. } => {
// TODO: Configurable step and limits // TODO: Configurable step and limits
if y > 0.0 { if y > 0.0 {
self.state.scale = Some( self.state.scale = Some(
@ -184,24 +169,19 @@ where
} }
} }
} }
Event::Mouse(mouse::Event::Input { button, state }) => { Event::Mouse(mouse::Event::ButtonPressed(button)) => {
if button == mouse::Button::Left { if button == mouse::Button::Left {
match state { self.state.starting_cursor_pos =
input::ButtonState::Pressed => { Some((cursor_position.x, cursor_position.y));
self.state.starting_cursor_pos = Some((
cursor_position.x,
cursor_position.y,
));
self.state.starting_offset = self.state.starting_offset = self.state.current_offset;
self.state.current_offset;
} }
input::ButtonState::Released => { }
Event::Mouse(mouse::Event::ButtonReleased(button)) => {
if button == mouse::Button::Left {
self.state.starting_cursor_pos = None self.state.starting_cursor_pos = None
} }
} }
}
}
Event::Mouse(mouse::Event::CursorMoved { x, y }) => { Event::Mouse(mouse::Event::CursorMoved { x, y }) => {
if self.state.is_cursor_clicked() { if self.state.is_cursor_clicked() {
self.state.pan(x, y, bounds, image_bounds); self.state.pan(x, y, bounds, image_bounds);
@ -209,12 +189,9 @@ where
} }
_ => {} _ => {}
} }
} else if let Event::Mouse(mouse::Event::Input { button, state }) = } else if let Event::Mouse(mouse::Event::ButtonReleased(button)) = event
event
{
if button == mouse::Button::Left
&& state == input::ButtonState::Released
{ {
if button == mouse::Button::Left {
self.state.starting_cursor_pos = None; self.state.starting_cursor_pos = None;
} }
} }

View File

@ -1,5 +1,5 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{image, image_pane, MouseCursor, Rectangle, Vector}; use iced_native::{image, image_pane, mouse, Rectangle, Vector};
impl image_pane::Renderer for Renderer { impl image_pane::Renderer for Renderer {
fn draw( fn draw(
@ -24,14 +24,14 @@ impl image_pane::Renderer for Renderer {
}, },
{ {
if state.is_cursor_clicked() { if state.is_cursor_clicked() {
MouseCursor::Grabbing mouse::Interaction::Grabbing
} else if is_mouse_over } else if is_mouse_over
&& (image_bounds.width > bounds.width && (image_bounds.width > bounds.width
|| image_bounds.height > bounds.height) || image_bounds.height > bounds.height)
{ {
MouseCursor::Grab mouse::Interaction::Grab
} else { } else {
MouseCursor::Idle mouse::Interaction::Idle
} }
}, },
) )