summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-12-18 10:24:04 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-12-18 10:24:04 +0100
commit71de341684e27568c620c65e6b9e8e9ec837183c (patch)
tree3203d046327feb0972412db53ee2b9f265284971 /native
parent74ee7cca811d6f462ca253bced4e3f07e52d9300 (diff)
downloadiced-71de341684e27568c620c65e6b9e8e9ec837183c.tar.gz
iced-71de341684e27568c620c65e6b9e8e9ec837183c.tar.bz2
iced-71de341684e27568c620c65e6b9e8e9ec837183c.zip
Turn methods into helper functions in `image::viewer`
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/image/viewer.rs46
1 files changed, 20 insertions, 26 deletions
diff --git a/native/src/widget/image/viewer.rs b/native/src/widget/image/viewer.rs
index 9544beab..3ffdf2c0 100644
--- a/native/src/widget/image/viewer.rs
+++ b/native/src/widget/image/viewer.rs
@@ -132,7 +132,7 @@ impl<'a> Viewer<'a> {
{
let (width, height) = renderer.dimensions(&self.handle);
- let dimensions = {
+ let (width, height) = {
let dimensions = (width as f32, height as f32);
let width_ratio = bounds.width / dimensions.0;
@@ -152,33 +152,27 @@ impl<'a> Viewer<'a> {
Rectangle {
x: bounds.x,
y: bounds.y,
- width: dimensions.0,
- height: dimensions.1,
+ width,
+ height,
}
}
+}
- /// Cursor position relative to the [`Viewer`] bounds.
- ///
- /// [`Viewer`]: struct.Viewer.html
- fn relative_cursor_position(
- &self,
- mut absolute_position: Point,
- bounds: Rectangle,
- ) -> Point {
- absolute_position.x -= bounds.x;
- absolute_position.y -= bounds.y;
- absolute_position
- }
+/// Cursor position relative to the [`Viewer`] bounds.
+///
+/// [`Viewer`]: struct.Viewer.html
+fn relative_cursor_position(
+ absolute_position: Point,
+ bounds: Rectangle,
+) -> Point {
+ absolute_position - Vector::new(bounds.x, bounds.y)
+}
- /// Center point relative to the [`Viewer`] bounds.
- ///
- /// [`Viewer`]: struct.Viewer.html
- fn relative_center(&self, bounds: Rectangle) -> Point {
- let mut center = bounds.center();
- center.x -= bounds.x;
- center.y -= bounds.y;
- center
- }
+/// Center point relative to the [`Viewer`] bounds.
+///
+/// [`Viewer`]: struct.Viewer.html
+fn relative_center(bounds: Rectangle) -> Point {
+ bounds.center() - Vector::new(bounds.x, bounds.y)
}
impl<'a, Message, Renderer> Widget<Message, Renderer> for Viewer<'a>
@@ -256,10 +250,10 @@ where
- 1.0;
let cursor_to_center =
- self.relative_cursor_position(
+ relative_cursor_position(
cursor_position,
bounds,
- ) - self.relative_center(bounds);
+ ) - relative_center(bounds);
let adjustment = cursor_to_center * factor
+ self.state.current_offset * factor;