From 4add755a4d72132324be5cfd04fd119850519b5b Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 15 Dec 2024 10:53:15 +0300 Subject: layout/floating: Extract move_and_animate() --- src/layout/floating.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/layout/floating.rs b/src/layout/floating.rs index 271ab314..c3cf8831 100644 --- a/src/layout/floating.rs +++ b/src/layout/floating.rs @@ -697,13 +697,9 @@ impl FloatingSpace { }; let active_idx = self.idx_of(active_id).unwrap(); - let tile = &mut self.tiles[active_idx]; - let data = &mut self.data[active_idx]; - - let prev_pos = data.logical_pos; - let new_pos = center_preferring_top_left_in_area(self.working_area, data.size); - data.set_logical_pos(new_pos); - tile.animate_move_from(prev_pos - new_pos); + let new_pos = + center_preferring_top_left_in_area(self.working_area, self.data[active_idx].size); + self.move_and_animate(active_idx, new_pos); } pub fn descendants_added(&mut self, id: &W::Id) -> bool { @@ -907,6 +903,23 @@ impl FloatingSpace { rect.loc } + fn move_and_animate(&mut self, idx: usize, new_pos: Point) { + // Moves up to this logical pixel distance are not animated. + const ANIMATION_THRESHOLD_SQ: f64 = 10. * 10.; + + let tile = &mut self.tiles[idx]; + let data = &mut self.data[idx]; + + let prev_pos = data.logical_pos; + data.set_logical_pos(new_pos); + let new_pos = data.logical_pos; + + let diff = prev_pos - new_pos; + if diff.x * diff.x + diff.y * diff.y > ANIMATION_THRESHOLD_SQ { + tile.animate_move_from(prev_pos - new_pos); + } + } + #[cfg(test)] pub fn working_area(&self) -> Rectangle { self.working_area -- cgit