From a9f0f4d44f911400ab26d3375dbc2a4015ebb7e5 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 14 Aug 2025 15:18:18 +0300 Subject: layout/scrolling: Normalize column X move anim from 1 to 0 Will be needed for offsetting to fix the resize cancel issue. --- src/layout/scrolling.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'src/layout') diff --git a/src/layout/scrolling.rs b/src/layout/scrolling.rs index 1d43ac56..5dfbb6ef 100644 --- a/src/layout/scrolling.rs +++ b/src/layout/scrolling.rs @@ -176,7 +176,7 @@ pub struct Column { tab_indicator: TabIndicator, /// Animation of the render offset during window swapping. - move_animation: Option, + move_animation: Option, /// Latest known view size for this column's workspace. view_size: Size, @@ -254,6 +254,12 @@ pub enum ScrollDirection { Right, } +#[derive(Debug)] +struct MoveAnimation { + anim: Animation, + from: f64, +} + impl ScrollingSpace { pub fn new( view_size: Size, @@ -3878,8 +3884,8 @@ impl Column { } pub fn advance_animations(&mut self) { - if let Some(anim) = &mut self.move_animation { - if anim.is_done() { + if let Some(move_) = &mut self.move_animation { + if move_.anim.is_done() { self.move_animation = None; } } @@ -3944,8 +3950,8 @@ impl Column { pub fn render_offset(&self) -> Point { let mut offset = Point::from((0., 0.)); - if let Some(anim) = &self.move_animation { - offset.x += anim.value(); + if let Some(move_) = &self.move_animation { + offset.x += move_.from * move_.anim.value(); } offset @@ -3963,15 +3969,16 @@ impl Column { from_x_offset: f64, config: niri_config::Animation, ) { - let current_offset = self.move_animation.as_ref().map_or(0., Animation::value); - - self.move_animation = Some(Animation::new( - self.clock.clone(), - from_x_offset + current_offset, - 0., - 0., - config, - )); + let current_offset = self + .move_animation + .as_ref() + .map_or(0., |move_| move_.from * move_.anim.value()); + + let anim = Animation::new(self.clock.clone(), 1., 0., 0., config); + self.move_animation = Some(MoveAnimation { + anim, + from: from_x_offset + current_offset, + }); } pub fn contains(&self, window: &W::Id) -> bool { -- cgit