layout: Offset ongoing column X move anims for non-animated resizes
Browse files at this commit25c1c0434907ebee85b1e9df5fd5ef60fa1a15fdParent: 36af02a2 changed files +54 -22
- src/layout/scrolling.rs +48 -12
- src/layout/tests/animations.rs +6 -10
src/layout/scrolling.rsmodified+48 -12
| @@ -1249,22 +1249,47 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 1249 | let offset = prev_width - self.data[col_idx].width; | 1249 | let offset = prev_width - self.data[col_idx].width; |
| 1250 | 1250 | ||
| 1251 | // Move other columns in tandem with resizing. | 1251 | // Move other columns in tandem with resizing. |
| 1252 | - let started_resize_anim = | 1252 | + let ongoing_resize_anim = column.tiles[tile_idx].resize_animation().is_some(); |
| 1253 | - column.tiles[tile_idx].resize_animation().is_some() && offset != 0.; | 1253 | + if offset != 0. { |
| 1254 | - if started_resize_anim { | ||
| 1255 | if self.active_column_idx <= col_idx { | 1254 | if self.active_column_idx <= col_idx { |
| 1256 | for col in &mut self.columns[col_idx + 1..] { | 1255 | for col in &mut self.columns[col_idx + 1..] { |
| 1257 | - col.animate_move_from_with_config( | 1256 | + // If there's a resize animation on the tile (that may have just started in |
| 1258 | - offset, | 1257 | + // column.update_window()), then the apparent size change is smooth with no |
| 1259 | - self.options.animations.window_resize.anim, | 1258 | + // sudden jumps. This corresponds to adding an X animation to adjacent columns. |
| 1260 | - ); | 1259 | + // |
| 1260 | + // There could also be no resize animation with nonzero offset. This could | ||
| 1261 | + // happen for example: | ||
| 1262 | + // - if the window resized on its own, which we don't animate | ||
| 1263 | + // - if the window resized by less than 10 px (the resize threshold) | ||
| 1264 | + // | ||
| 1265 | + // The latter case could also cancel an ongoing resize animation. | ||
| 1266 | + // | ||
| 1267 | + // Now, stationary columns shouldn't react to this offset change in any way, | ||
| 1268 | + // i.e. their apparent X position should jump together with the resize. | ||
| 1269 | + // However, adjacent columns that are already animating an X movement should | ||
| 1270 | + // offset their animations to avoid the jump. | ||
| 1271 | + // | ||
| 1272 | + // Notably, this is necessary to fix the animation jump when resizing width back | ||
| 1273 | + // and forth in quick succession (in a way that cancels the resize animation). | ||
| 1274 | + if ongoing_resize_anim { | ||
| 1275 | + col.animate_move_from_with_config( | ||
| 1276 | + offset, | ||
| 1277 | + self.options.animations.window_resize.anim, | ||
| 1278 | + ); | ||
| 1279 | + } else { | ||
| 1280 | + col.offset_move_anim_current(offset); | ||
| 1281 | + } | ||
| 1261 | } | 1282 | } |
| 1262 | } else { | 1283 | } else { |
| 1263 | for col in &mut self.columns[..=col_idx] { | 1284 | for col in &mut self.columns[..=col_idx] { |
| 1264 | - col.animate_move_from_with_config( | 1285 | + if ongoing_resize_anim { |
| 1265 | - -offset, | 1286 | + col.animate_move_from_with_config( |
| 1266 | - self.options.animations.window_resize.anim, | 1287 | + -offset, |
| 1267 | - ); | 1288 | + self.options.animations.window_resize.anim, |
| 1289 | + ); | ||
| 1290 | + } else { | ||
| 1291 | + col.offset_move_anim_current(-offset); | ||
| 1292 | + } | ||
| 1268 | } | 1293 | } |
| 1269 | } | 1294 | } |
| 1270 | } | 1295 | } |
| @@ -1323,7 +1348,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 1323 | 1348 | ||
| 1324 | // Synchronize the horizontal view movement with the resize so that it looks nice. | 1349 | // Synchronize the horizontal view movement with the resize so that it looks nice. |
| 1325 | // This is especially important for always-centered view. | 1350 | // This is especially important for always-centered view. |
| 1326 | - let config = if started_resize_anim { | 1351 | + let config = if ongoing_resize_anim { |
| 1327 | self.options.animations.window_resize.anim | 1352 | self.options.animations.window_resize.anim |
| 1328 | } else { | 1353 | } else { |
| 1329 | self.options.animations.horizontal_view_movement.0 | 1354 | self.options.animations.horizontal_view_movement.0 |
| @@ -3981,6 +4006,17 @@ impl<W: LayoutElement> Column<W> { | |||
| 3981 | }); | 4006 | }); |
| 3982 | } | 4007 | } |
| 3983 | 4008 | ||
| 4009 | + pub fn offset_move_anim_current(&mut self, offset: f64) { | ||
| 4010 | + if let Some(move_) = self.move_animation.as_mut() { | ||
| 4011 | + // If the anim is almost done, there's little point trying to offset it; we can let | ||
| 4012 | + // things jump. If it turns out like a bad idea, we could restart the anim intead. | ||
| 4013 | + let value = move_.anim.value(); | ||
| 4014 | + if value > 0.001 { | ||
| 4015 | + move_.from += offset / value; | ||
| 4016 | + } | ||
| 4017 | + } | ||
| 4018 | + } | ||
| 4019 | + | ||
| 3984 | pub fn contains(&self, window: &W::Id) -> bool { | 4020 | pub fn contains(&self, window: &W::Id) -> bool { |
| 3985 | self.tiles | 4021 | self.tiles |
| 3986 | .iter() | 4022 | .iter() |
src/layout/tests/animations.rsmodified+6 -10
| @@ -989,16 +989,14 @@ fn width_resize_and_cancel() { | |||
| 989 | check_ops_on_layout(&mut layout, &ops); | 989 | check_ops_on_layout(&mut layout, &ops); |
| 990 | 990 | ||
| 991 | // Since the resize animation is cancelled, the width goes to the new value immediately. The X | 991 | // Since the resize animation is cancelled, the width goes to the new value immediately. The X |
| 992 | - // position doesn't jump, instead the animation is offset to preserve the current position. | 992 | + // position doesn't jump, instead the animation is restarted to preserve the current position. |
| 993 | - // | ||
| 994 | - // FIXME: this is not currently the case! | ||
| 995 | assert_snapshot!(format_tiles(&layout), @r" | 993 | assert_snapshot!(format_tiles(&layout), @r" |
| 996 | 100 × 100 at x: 0 y: 0 | 994 | 100 × 100 at x: 0 y: 0 |
| 997 | - 200 × 200 at x: 5 y: 0 | 995 | + 200 × 200 at x:105 y: 0 |
| 998 | "); | 996 | "); |
| 999 | 997 | ||
| 1000 | // Advance to the end of the move animation. | 998 | // Advance to the end of the move animation. |
| 1001 | - Op::AdvanceAnimations { msec_delta: 950 }.apply(&mut layout); | 999 | + Op::AdvanceAnimations { msec_delta: 1000 }.apply(&mut layout); |
| 1002 | 1000 | ||
| 1003 | // Final state. | 1001 | // Final state. |
| 1004 | assert_snapshot!(format_tiles(&layout), @r" | 1002 | assert_snapshot!(format_tiles(&layout), @r" |
| @@ -1081,16 +1079,14 @@ fn width_resize_and_cancel_of_column_to_the_left() { | |||
| 1081 | check_ops_on_layout(&mut layout, &ops); | 1079 | check_ops_on_layout(&mut layout, &ops); |
| 1082 | 1080 | ||
| 1083 | // Since the resize animation is cancelled, the width goes to the new value immediately. The X | 1081 | // Since the resize animation is cancelled, the width goes to the new value immediately. The X |
| 1084 | - // position doesn't jump, instead the animation is offset to preserve the current position. | 1082 | + // position doesn't jump, instead the animation is restarted to preserve the current position. |
| 1085 | - // | ||
| 1086 | - // FIXME: this is not currently the case! | ||
| 1087 | assert_snapshot!(format_tiles(&layout), @r" | 1083 | assert_snapshot!(format_tiles(&layout), @r" |
| 1088 | - 100 × 100 at x: 95 y: 0 | 1084 | + 100 × 100 at x: -5 y: 0 |
| 1089 | 200 × 200 at x:100 y: 0 | 1085 | 200 × 200 at x:100 y: 0 |
| 1090 | "); | 1086 | "); |
| 1091 | 1087 | ||
| 1092 | // Advance to the end of the move animation. | 1088 | // Advance to the end of the move animation. |
| 1093 | - Op::AdvanceAnimations { msec_delta: 950 }.apply(&mut layout); | 1089 | + Op::AdvanceAnimations { msec_delta: 1000 }.apply(&mut layout); |
| 1094 | 1090 | ||
| 1095 | // Final state. | 1091 | // Final state. |
| 1096 | assert_snapshot!(format_tiles(&layout), @r" | 1092 | assert_snapshot!(format_tiles(&layout), @r" |