Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Time animations with the executor clock (#66317)
Anthony Eid99e70ee4a02d
diff --git a/crates/gpui/src/elements/animation.rs b/crates/gpui/src/elements/animation.rsindex e0768935d91..70613f38c5a 100644--- a/crates/gpui/src/elements/animation.rs+++ b/crates/gpui/src/elements/animation.rs@@ -268,7 +268,7 @@ impl<E: IntoElement + 'static> Element for SpringAnimationElement<E> {cx: &mut App,) -> (crate::LayoutId, Self::RequestLayoutState) {window.with_element_state(global_id.unwrap(), |state, window| {- let now = Instant::now();+ let now = cx.background_executor().now();let initial = self.initial.unwrap_or(self.target);let mut state = state.unwrap_or_else(|| SpringElementState {spring: SpringState {@@ -400,7 +400,7 @@ impl<E: IntoElement + 'static> Element for AnimationElement<E> {) -> (crate::LayoutId, Self::RequestLayoutState) {window.with_element_state(global_id.unwrap(), |state, window| {let mut state = state.unwrap_or_else(|| AnimationState {- start: Instant::now(),+ start: cx.background_executor().now(),animation_ix: 0,delayed_frame_pending: Rc::new(Cell::new(false)),});@@ -421,7 +421,7 @@ impl<E: IntoElement + 'static> Element for AnimationElement<E> {// Reduce modulo the duration before f32 conversion, which loses sub-second precision at scale.Duration::from_nanos((elapsed.as_nanos() % duration.as_nanos()) as u64)} else {- state.start.elapsed()+ cx.background_executor().now() - state.start};let mut delta = elapsed.as_secs_f32() / duration.as_secs_f32();@@ -431,7 +431,7 @@ impl<E: IntoElement + 'static> Element for AnimationElement<E> {if animation_ix >= self.animations.len() - 1 {done = true;} else {- state.start = Instant::now();+ state.start = cx.background_executor().now();state.animation_ix += 1;}delta = 1.0;