Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Add ParentElement impl for AnimationElement (#54145)
Nick Moshere7803a88f55e
diff --git a/crates/gpui/src/elements/animation.rs b/crates/gpui/src/elements/animation.rsindex 8a42c8bd492..b816f7dd935 100644--- a/crates/gpui/src/elements/animation.rs+++ b/crates/gpui/src/elements/animation.rs@@ -2,7 +2,8 @@ use scheduler::Instant;use std::{rc::Rc, time::Duration};use crate::{- AnyElement, App, Element, ElementId, GlobalElementId, InspectorElementId, IntoElement, Window,+ AnyElement, App, Element, ElementId, GlobalElementId, InspectorElementId, IntoElement,+ ParentElement, Window,};pub use easing::*;@@ -95,6 +96,16 @@ pub struct AnimationElement<E> {animator: Box<dyn Fn(E, usize, f32) -> E + 'static>,}+impl<E: ParentElement> ParentElement for AnimationElement<E> {+ fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {+ let Some(element) = &mut self.element else {+ return;+ };++ element.extend(elements);+ }+}+impl<E> AnimationElement<E> {/// Returns a new [`AnimationElement<E>`] after applying the given function/// to the element being animated.@@ -259,3 +270,33 @@ mod easing {}}}++#[cfg(test)]+mod tests {+ use crate::InteractiveElement;+ use crate::div;++ use super::*;++ // Before parent-animation-element, using .with_animation+ // would not allow chaining .parent after. This is just a+ // build check that we can call div().id().with_animation().child()+ #[test]+ fn test_animation_parent() {+ div()+ .id("id")+ //+ .with_animation(+ "animation",+ Animation::new(Duration::from_secs(1)),+ |el, _t| {+ //+ el+ },+ )+ .child(+ //+ div(),+ );+ }+}