diff --git a/crates/gpui/src/elements/animation.rs b/crates/gpui/src/elements/animation.rs index 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 { animator: Box E + 'static>, } +impl ParentElement for AnimationElement { + fn extend(&mut self, elements: impl IntoIterator) { + let Some(element) = &mut self.element else { + return; + }; + + element.extend(elements); + } +} + impl AnimationElement { /// Returns a new [`AnimationElement`] 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(), + ); + } +}