From f16bd898d6ff26654f94d08a38183ad77a36b3a1 Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Tue, 6 Aug 2024 14:00:43 +0200 Subject: [PATCH] image/zoom: No different callbacks for animation We actually don't need different callbacks for zooms with different targets anymore since the target is an object property anyways. --- ...ed-rotating-image-might-not-follow-best-fit | 1 + src/widgets/image/zoom.rs | 18 +++++------------- 2 files changed, 6 insertions(+), 13 deletions(-) create mode 100644 news.d/47.rc/fixed-rotating-image-might-not-follow-best-fit diff --git a/news.d/47.rc/fixed-rotating-image-might-not-follow-best-fit b/news.d/47.rc/fixed-rotating-image-might-not-follow-best-fit new file mode 100644 index 0000000..7a22d2c --- /dev/null +++ b/news.d/47.rc/fixed-rotating-image-might-not-follow-best-fit @@ -0,0 +1 @@ +Rotating a freshly opened image would not follow the best-fit scaling. diff --git a/src/widgets/image/zoom.rs b/src/widgets/image/zoom.rs index addcd56..8247e9d 100644 --- a/src/widgets/image/zoom.rs +++ b/src/widgets/image/zoom.rs @@ -263,25 +263,17 @@ impl imp::LpImage { let animation = self.zoom_animation(); if force_cursor_center { - animation.set_target(&adw::CallbackAnimationTarget::new(glib::clone!( - #[weak] - obj, - move |zoom| { - obj.imp().set_zoom_aiming(zoom, None); - } - ))); + self.zoom_cursor_target.set(None); } else { // Set new point in image that should remain under the cursor while zooming if // there isn't one already if self.zoom_cursor_target.get().is_none() { - let img_pos = self + let img_pos: Option<(f64, f64)> = self .pointer_position .get() .map(|x| self.widget_to_img_coord(x)); self.zoom_cursor_target.set(img_pos); } - - animation.set_target(&adw::PropertyAnimationTarget::new(&obj, "zoom")); } animation.set_value_from(obj.zoom()); @@ -296,13 +288,13 @@ impl imp::LpImage { /// Animation that makes larger zoom steps (from buttons etc) look smooth pub(super) fn zoom_animation(&self) -> &adw::TimedAnimation { self.zoom_animation.get_or_init(|| { - let obj = self.obj(); + let obj = self.obj().to_owned(); let animation = adw::TimedAnimation::builder() .duration(ZOOM_ANIMATION_DURATION) - .widget(&*obj) + .widget(&obj) // The actual target will be set individually later - .target(&adw::CallbackAnimationTarget::new(|_| {})) + .target(&adw::PropertyAnimationTarget::new(&obj, "zoom")) .build(); animation.connect_done(glib::clone!(