Skip to content

Commit

Permalink
Rebase to master and update for api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed May 14, 2020
1 parent e051fa8 commit bf32827
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
55 changes: 16 additions & 39 deletions native/src/widget/image_pane.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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(
Expand All @@ -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_offset =
self.state.current_offset;
}
input::ButtonState::Released => {
self.state.starting_cursor_pos = None
}
}
self.state.starting_cursor_pos =
Some((cursor_position.x, cursor_position.y));

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 }) => {
Expand All @@ -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;
}
}
Expand Down
8 changes: 4 additions & 4 deletions wgpu/src/renderer/widget/image_pane.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
}
},
)
Expand Down

0 comments on commit bf32827

Please sign in to comment.