layout/scrolling: Normalize column X move anim from 1 to 0
Browse files at this commita9f0f4d44f911400ab26d3375dbc2a4015ebb7e5Parent: e3101ce1 changed file +21 -14
- src/layout/scrolling.rs +21 -14
src/layout/scrolling.rsmodified+21 -14
| @@ -176,7 +176,7 @@ pub struct Column<W: LayoutElement> { | |||
| 176 | tab_indicator: TabIndicator, | 176 | tab_indicator: TabIndicator, |
| 177 | 177 | ||
| 178 | /// Animation of the render offset during window swapping. | 178 | /// Animation of the render offset during window swapping. |
| 179 | - move_animation: Option<Animation>, | 179 | + move_animation: Option<MoveAnimation>, |
| 180 | 180 | ||
| 181 | /// Latest known view size for this column's workspace. | 181 | /// Latest known view size for this column's workspace. |
| 182 | view_size: Size<f64, Logical>, | 182 | view_size: Size<f64, Logical>, |
| @@ -254,6 +254,12 @@ pub enum ScrollDirection { | |||
| 254 | Right, | 254 | Right, |
| 255 | } | 255 | } |
| 256 | 256 | ||
| 257 | +#[derive(Debug)] | ||
| 258 | +struct MoveAnimation { | ||
| 259 | + anim: Animation, | ||
| 260 | + from: f64, | ||
| 261 | +} | ||
| 262 | + | ||
| 257 | impl<W: LayoutElement> ScrollingSpace<W> { | 263 | impl<W: LayoutElement> ScrollingSpace<W> { |
| 258 | pub fn new( | 264 | pub fn new( |
| 259 | view_size: Size<f64, Logical>, | 265 | view_size: Size<f64, Logical>, |
| @@ -3878,8 +3884,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 3878 | } | 3884 | } |
| 3879 | 3885 | ||
| 3880 | pub fn advance_animations(&mut self) { | 3886 | pub fn advance_animations(&mut self) { |
| 3881 | - if let Some(anim) = &mut self.move_animation { | 3887 | + if let Some(move_) = &mut self.move_animation { |
| 3882 | - if anim.is_done() { | 3888 | + if move_.anim.is_done() { |
| 3883 | self.move_animation = None; | 3889 | self.move_animation = None; |
| 3884 | } | 3890 | } |
| 3885 | } | 3891 | } |
| @@ -3944,8 +3950,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 3944 | pub fn render_offset(&self) -> Point<f64, Logical> { | 3950 | pub fn render_offset(&self) -> Point<f64, Logical> { |
| 3945 | let mut offset = Point::from((0., 0.)); | 3951 | let mut offset = Point::from((0., 0.)); |
| 3946 | 3952 | ||
| 3947 | - if let Some(anim) = &self.move_animation { | 3953 | + if let Some(move_) = &self.move_animation { |
| 3948 | - offset.x += anim.value(); | 3954 | + offset.x += move_.from * move_.anim.value(); |
| 3949 | } | 3955 | } |
| 3950 | 3956 | ||
| 3951 | offset | 3957 | offset |
| @@ -3963,15 +3969,16 @@ impl<W: LayoutElement> Column<W> { | |||
| 3963 | from_x_offset: f64, | 3969 | from_x_offset: f64, |
| 3964 | config: niri_config::Animation, | 3970 | config: niri_config::Animation, |
| 3965 | ) { | 3971 | ) { |
| 3966 | - let current_offset = self.move_animation.as_ref().map_or(0., Animation::value); | 3972 | + let current_offset = self |
| 3967 | - | 3973 | + .move_animation |
| 3968 | - self.move_animation = Some(Animation::new( | 3974 | + .as_ref() |
| 3969 | - self.clock.clone(), | 3975 | + .map_or(0., |move_| move_.from * move_.anim.value()); |
| 3970 | - from_x_offset + current_offset, | 3976 | + |
| 3971 | - 0., | 3977 | + let anim = Animation::new(self.clock.clone(), 1., 0., 0., config); |
| 3972 | - 0., | 3978 | + self.move_animation = Some(MoveAnimation { |
| 3973 | - config, | 3979 | + anim, |
| 3974 | - )); | 3980 | + from: from_x_offset + current_offset, |
| 3981 | + }); | ||
| 3975 | } | 3982 | } |
| 3976 | 3983 | ||
| 3977 | pub fn contains(&self, window: &W::Id) -> bool { | 3984 | pub fn contains(&self, window: &W::Id) -> bool { |