-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from tarkah/image-pane
Add `ImagePane` widget
- Loading branch information
Showing
7 changed files
with
466 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! Zoom and pan on an image. | ||
use crate::backend::{self, Backend}; | ||
use crate::{Primitive, Renderer}; | ||
|
||
use iced_native::image; | ||
use iced_native::image::viewer; | ||
use iced_native::mouse; | ||
use iced_native::{Rectangle, Size, Vector}; | ||
|
||
impl<B> viewer::Renderer for Renderer<B> | ||
where | ||
B: Backend + backend::Image, | ||
{ | ||
fn draw( | ||
&mut self, | ||
state: &viewer::State, | ||
bounds: Rectangle, | ||
image_size: Size, | ||
translation: Vector, | ||
handle: image::Handle, | ||
is_mouse_over: bool, | ||
) -> Self::Output { | ||
( | ||
{ | ||
Primitive::Clip { | ||
bounds, | ||
content: Box::new(Primitive::Translate { | ||
translation, | ||
content: Box::new(Primitive::Image { | ||
handle, | ||
bounds: Rectangle { | ||
x: bounds.x, | ||
y: bounds.y, | ||
..Rectangle::with_size(image_size) | ||
}, | ||
}), | ||
}), | ||
offset: Vector::new(0, 0), | ||
} | ||
}, | ||
{ | ||
if state.is_cursor_grabbed() { | ||
mouse::Interaction::Grabbing | ||
} else if is_mouse_over | ||
&& (image_size.width > bounds.width | ||
|| image_size.height > bounds.height) | ||
{ | ||
mouse::Interaction::Grab | ||
} else { | ||
mouse::Interaction::Idle | ||
} | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.