Add tolerance to view offset anim restart check
Browse files at this commit22bfec7259282c4e7f629b502e171dbf7580b5a1Parent: 1af9f9b1 changed file +10 -4
- src/layout/workspace.rs +10 -4
src/layout/workspace.rsmodified+10 -4
| @@ -771,16 +771,22 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 771 | 771 | let from_view_offset = current_x - new_col_x; |
| 772 | 772 | self.view_offset = from_view_offset; |
| 773 | 773 | |
| 774 | + let pixel = 1. / self.scale.fractional_scale(); | |
| 775 | + | |
| 774 | 776 | // If we're already animating towards that, don't restart it. |
| 775 | - if let Some(ViewOffsetAdjustment::Animation(anim)) = &self.view_offset_adj { | |
| 776 | - let pixel = 1. / self.scale.fractional_scale(); | |
| 777 | - if (anim.value() - self.view_offset).abs() < pixel && anim.to() == new_view_offset { | |
| 777 | + if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj { | |
| 778 | + let to_diff = new_view_offset - anim.to(); | |
| 779 | + if (anim.value() - self.view_offset).abs() < pixel && to_diff.abs() < pixel { | |
| 780 | + // Correct for any inaccuracy. | |
| 781 | + anim.offset(to_diff); | |
| 778 | 782 | return; |
| 779 | 783 | } |
| 780 | 784 | } |
| 781 | 785 | |
| 782 | 786 | // If our view offset is already this, we don't need to do anything. |
| 783 | - if self.view_offset == new_view_offset { | |
| 787 | + if (self.view_offset - new_view_offset).abs() < pixel { | |
| 788 | + // Correct for any inaccuracy. | |
| 789 | + self.view_offset = new_view_offset; | |
| 784 | 790 | self.view_offset_adj = None; |
| 785 | 791 | return; |
| 786 | 792 | } |