From e448cfb0efee0efbfc769662ee77ad22a347dc02 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 8 Apr 2024 22:16:11 +0400 Subject: Adjust view offset anim together with offset Not doing this caused quickly moving a column right and left to base the final view position on an incorrect view offset. --- src/animation/mod.rs | 10 ++++++++++ src/layout/workspace.rs | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/animation/mod.rs b/src/animation/mod.rs index 7984b0d9..d8e8cbd5 100644 --- a/src/animation/mod.rs +++ b/src/animation/mod.rs @@ -261,6 +261,16 @@ impl Animation { pub fn from(&self) -> f64 { self.from } + + pub fn offset(&mut self, offset: f64) { + self.from += offset; + self.to += offset; + + if let Kind::Spring(spring) = &mut self.kind { + spring.from += offset; + spring.to += offset; + } + } } impl Curve { diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index f5b425bd..f337a74a 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -963,13 +963,15 @@ impl Workspace { let current_col_x = self.column_x(self.active_column_idx); let next_col_x = self.column_x(self.active_column_idx + 1); - let current_x = current_col_x + self.view_offset; - let column = self.columns.remove(self.active_column_idx); self.columns.insert(new_idx, column); // Preserve the camera position when moving to the left. - self.view_offset = current_x - self.column_x(self.active_column_idx); + let view_offset_delta = -self.column_x(self.active_column_idx) + current_col_x; + self.view_offset += view_offset_delta; + if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj { + anim.offset(view_offset_delta as f64); + } // The column we just moved is offset by the difference between its new and old position. let new_col_x = self.column_x(new_idx); -- cgit