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.
use crate::{
image,
input::{self, mouse},
layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Rectangle, Size, Widget,
image, layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length,
Point, Rectangle, Size, Widget,
};
use std::{f32, hash::Hash, u32};
@ -154,21 +152,8 @@ where
match event {
Event::Mouse(mouse::Event::WheelScrolled { delta }) => {
match delta {
mouse::ScrollDelta::Lines { y, .. } => {
// TODO: Configurable step and limits
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, .. } => {
mouse::ScrollDelta::Lines { y, .. }
| mouse::ScrollDelta::Pixels { y, .. } => {
// TODO: Configurable step and limits
if y > 0.0 {
self.state.scale = Some(
@ -184,22 +169,17 @@ where
}
}
}
Event::Mouse(mouse::Event::Input { button, state }) => {
Event::Mouse(mouse::Event::ButtonPressed(button)) => {
if button == mouse::Button::Left {
match state {
input::ButtonState::Pressed => {
self.state.starting_cursor_pos = 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.current_offset;
}
input::ButtonState::Released => {
self.state.starting_cursor_pos = None
}
}
self.state.starting_offset = self.state.current_offset;
}
}
Event::Mouse(mouse::Event::ButtonReleased(button)) => {
if button == mouse::Button::Left {
self.state.starting_cursor_pos = None
}
}
Event::Mouse(mouse::Event::CursorMoved { x, y }) => {
@ -209,12 +189,9 @@ where
}
_ => {}
}
} else if let Event::Mouse(mouse::Event::Input { button, state }) =
event
} else if let Event::Mouse(mouse::Event::ButtonReleased(button)) = event
{
if button == mouse::Button::Left
&& state == input::ButtonState::Released
{
if button == mouse::Button::Left {
self.state.starting_cursor_pos = None;
}
}

View File

@ -1,5 +1,5 @@
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 {
fn draw(
@ -24,14 +24,14 @@ impl image_pane::Renderer for Renderer {
},
{
if state.is_cursor_clicked() {
MouseCursor::Grabbing
mouse::Interaction::Grabbing
} else if is_mouse_over
&& (image_bounds.width > bounds.width
|| image_bounds.height > bounds.height)
{
MouseCursor::Grab
mouse::Interaction::Grab
} else {
MouseCursor::Idle
mouse::Interaction::Idle
}
},
)