forge
Explore
Log in

Don't you dare go Hollow

layout: Offset Y animations for non-animated resizes

Browse files at this commit

e3101ced70b908d4fc9bceef47e878d2de2b4c5dIvan MolodetskikhParent: ea438b2
src/layout/scrolling.rsmodified+29 -6
@@ -4056,12 +4056,35 @@ impl<W: LayoutElement> Column<W> {
4056 // windows in the column, so they should all be animated. How should this interact with4056 // windows in the column, so they should all be animated. How should this interact with
4057 // animated vs. non-animated resizes? For example, an animated +20 resize followed by two4057 // animated vs. non-animated resizes? For example, an animated +20 resize followed by two
4058 // non-animated -10 resizes.4058 // non-animated -10 resizes.
4059- if !is_tabbed && tile.resize_animation().is_some() && offset != 0. {4059+ if !is_tabbed && offset != 0. {
4060- for tile in &mut self.tiles[tile_idx + 1..] {4060+ if tile.resize_animation().is_some() {
4061- tile.animate_move_y_from_with_config(4061+ // If there's a resize animation (that may have just started in
4062- offset,4062+ // tile.update_window()), then the apparent size change is smooth with no sudden
4063- self.options.animations.window_resize.anim,4063+ // jumps. This corresponds to adding an Y animation to tiles below.
4064- );4064+ for tile in &mut self.tiles[tile_idx + 1..] {
4065+ tile.animate_move_y_from_with_config(
4066+ offset,
4067+ self.options.animations.window_resize.anim,
4068+ );
4069+ }
4070+ } else {
4071+ // There's no resize animation, but the offset is nonzero. This could happen for
4072+ // example:
4073+ // - if the window resized on its own, which we don't animate
4074+ // - if the window resized by less than 10 px (the resize threshold)
4075+ //
4076+ // The latter case could also cancel an ongoing resize animation.
4077+ //
4078+ // Now, stationary tiles below shouldn't react to this offset change in any way,
4079+ // i.e. their apparent Y position should jump together with the resize. However,
4080+ // tiles below that are already animating an Y movement should offset their
4081+ // animations to avoid the jump.
4082+ //
4083+ // Notably, this is necessary to fix the animation jump when resizing height back
4084+ // and forth in quick succession (in a way that cancels the resize animation).
4085+ for tile in &mut self.tiles[tile_idx + 1..] {
4086+ tile.offset_move_y_anim_current(offset);
4087+ }
4065 }4088 }
4066 }4089 }
4067 }4090 }
src/layout/tests/animations.rsmodified+31 -25
@@ -269,14 +269,20 @@ fn height_resize_and_cancel() {
269 ];269 ];
270 check_ops_on_layout(&mut layout, &ops);270 check_ops_on_layout(&mut layout, &ops);
271 271
272- // Since the resize animation is cancelled, the height goes to the new value immediately, and272+ // Since the resize animation is cancelled, the height goes to the new value immediately. The Y
273- // the Y position should also go to 100 immediately, cancelling the movement.273+ // position doesn't jump, instead the animation is offset to preserve the current position.
274- //
275- // FIXME: right now, the Y position jumps to 5 and will continue animating to 100 from there
276- // because cancelling the resize anim doesn't cancel the induced Y movement.
277 assert_snapshot!(format_tiles(&layout), @r"274 assert_snapshot!(format_tiles(&layout), @r"
278 100 × 100 at x: 0 y: 0275 100 × 100 at x: 0 y: 0
279- 200 × 200 at x: 0 y: 5276+ 200 × 200 at x: 0 y:105
277+ ");
278+
279+ // Advance to the end of the move animation.
280+ Op::AdvanceAnimations { msec_delta: 950 }.apply(&mut layout);
281+
282+ // Final state.
283+ assert_snapshot!(format_tiles(&layout), @r"
284+ 100 × 100 at x: 0 y: 0
285+ 200 × 200 at x: 0 y:100
280 ");286 ");
281 }287 }
282 288
@@ -506,23 +512,30 @@ fn height_resize_and_cancel_during_another_y_anim() {
506 ];512 ];
507 check_ops_on_layout(&mut layout, &ops);513 check_ops_on_layout(&mut layout, &ops);
508 514
509- // Since the resize anim was cancelled, second window's Y should jump a little to go back to515+ // Since the resize anim was cancelled, second window's Y anim is adjusted to preserve the
510- // its original trajectory.516+ // current position while targeting the new final position.
511- //
512- // FIXME: right now, the Y position jumps and will continue to animate from there because
513- // cancelling the resize anim doesn't cancel the induced Y movement.
514 assert_snapshot!(format_tiles(&layout), @r"517 assert_snapshot!(format_tiles(&layout), @r"
515 100 × 100 at x: 0 y: 0518 100 × 100 at x: 0 y: 0
516- 200 × 200 at x: 45 y:-43519+ 200 × 200 at x: 45 y: 58
517 ");520 ");
518 521
519 // Advance the time to complete the consume movement.522 // Advance the time to complete the consume movement.
520 Op::AdvanceAnimations { msec_delta: 450 }.apply(&mut layout);523 Op::AdvanceAnimations { msec_delta: 450 }.apply(&mut layout);
521 524
522- // Final state. Y should be at 100 since the resize-induced Y anim was cancelled.525+ // Since we don't cancel the resize-induced part of the anim (in fact the move Y anim isn't
526+ // split into parts, so there's no way to tell), it keeps going still.
523 assert_snapshot!(format_tiles(&layout), @r"527 assert_snapshot!(format_tiles(&layout), @r"
524 100 × 100 at x: 0 y: 0528 100 × 100 at x: 0 y: 0
525- 200 × 200 at x: 0 y: 25529+ 200 × 200 at x: 0 y: 78
530+ ");
531+
532+ // Advance the time to complete the resize-induced anim.
533+ Op::AdvanceAnimations { msec_delta: 550 }.apply(&mut layout);
534+
535+ // Final state.
536+ assert_snapshot!(format_tiles(&layout), @r"
537+ 100 × 100 at x: 0 y: 0
538+ 200 × 200 at x: 0 y:100
526 ");539 ");
527 }540 }
528 541
@@ -723,14 +736,10 @@ fn height_resize_before_another_y_anim_then_cancel() {
723 ];736 ];
724 check_ops_on_layout(&mut layout, &ops);737 check_ops_on_layout(&mut layout, &ops);
725 738
726- // This should cause the second window's trajectory to readjust to the new final position at739+ // The second window's trajectory readjusts to the new final position at 100 px, without jumps.
727- // 100px. Ideally without big jumps because even though the first window's actual size changed
728- // from 200 px to 100 px, the cancelled resize only shifted it from 104 px to 100 px.
729- //
730- // FIXME: currently causes a 100 px jump due to the change in the actual window size.
731 assert_snapshot!(format_tiles(&layout), @r"740 assert_snapshot!(format_tiles(&layout), @r"
732 100 × 100 at x: 0 y: 0741 100 × 100 at x: 0 y: 0
733- 200 × 200 at x: 98 y:-96742+ 200 × 200 at x: 98 y: 4
734 ");743 ");
735 744
736 // Advance the time to complete the consume movement.745 // Advance the time to complete the consume movement.
@@ -791,13 +800,10 @@ fn clientside_height_change_during_another_y_anim() {
791 ];800 ];
792 check_ops_on_layout(&mut layout, &ops);801 check_ops_on_layout(&mut layout, &ops);
793 802
794- // This should cause the second window's trajectory to readjust to the new final position at803+ // The second window's trajectory readjusts to the new final position at 200 px, without jumps.
795- // 200px. Ideally without big jumps.
796- //
797- // FIXME: currently causes a 100 px jump due to the change in the window size.
798 assert_snapshot!(format_tiles(&layout), @r"804 assert_snapshot!(format_tiles(&layout), @r"
799 100 × 200 at x: 0 y: 0805 100 × 200 at x: 0 y: 0
800- 200 × 200 at x: 80 y:120806+ 200 × 200 at x: 80 y: 20
801 ");807 ");
802 808
803 // Advance the time to complete the consume movement.809 // Advance the time to complete the consume movement.
src/layout/tile.rsmodified+11 -0
@@ -485,6 +485,17 @@ impl<W: LayoutElement> Tile<W> {
485 });485 });
486 }486 }
487 487
488+ pub fn offset_move_y_anim_current(&mut self, offset: f64) {
489+ if let Some(move_) = self.move_y_animation.as_mut() {
490+ // If the anim is almost done, there's little point trying to offset it; we can let
491+ // things jump. If it turns out like a bad idea, we could restart the anim intead.
492+ let value = move_.anim.value();
493+ if value > 0.001 {
494+ move_.from += offset / value;
495+ }
496+ }
497+ }
498+
488 pub fn stop_move_animations(&mut self) {499 pub fn stop_move_animations(&mut self) {
489 self.move_x_animation = None;500 self.move_x_animation = None;
490 self.move_y_animation = None;501 self.move_y_animation = None;