mirror of
https://github.com/zed-industries/zed.git
synced 2026-07-10 00:13:29 +00:00
gpui: Add ParentElement impl for AnimationElement (#54145)
Hello, I've been loving using GPUI! Recently I noticed that calling `.with_animiation()` would give an `AnimationElement<E>` which did not allow `.child()` to be called on it. It was a quick fix, I hope it's a quick easy merge but let me know if you'd like anything changed :) Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - N/A Co-authored-by: Lukas Wirth <lukas@zed.dev>
This commit is contained in:
parent
a29c0d41f4
commit
e7803a88f5
1 changed files with 42 additions and 1 deletions
|
|
@ -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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue