gpui: Allow Animation to be cloned (#34933)
Release Notes: - N/A --- Let `Animation` able to clone, then we can define one to share for multiple places. For example: <img width="914" height="637" alt="image" src="https://github.com/user-attachments/assets/8eafb318-afba-4399-a975-d83cb7afe74c" />
This commit is contained in:
parent
11ac83f3d4
commit
3e27fa1d92
1 changed files with 8 additions and 4 deletions
|
@ -1,4 +1,7 @@
|
||||||
use std::time::{Duration, Instant};
|
use std::{
|
||||||
|
rc::Rc,
|
||||||
|
time::{Duration, Instant},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AnyElement, App, Element, ElementId, GlobalElementId, InspectorElementId, IntoElement, Window,
|
AnyElement, App, Element, ElementId, GlobalElementId, InspectorElementId, IntoElement, Window,
|
||||||
|
@ -8,6 +11,7 @@ pub use easing::*;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
/// An animation that can be applied to an element.
|
/// An animation that can be applied to an element.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Animation {
|
pub struct Animation {
|
||||||
/// The amount of time for which this animation should run
|
/// The amount of time for which this animation should run
|
||||||
pub duration: Duration,
|
pub duration: Duration,
|
||||||
|
@ -15,7 +19,7 @@ pub struct Animation {
|
||||||
pub oneshot: bool,
|
pub oneshot: bool,
|
||||||
/// A function that takes a delta between 0 and 1 and returns a new delta
|
/// A function that takes a delta between 0 and 1 and returns a new delta
|
||||||
/// between 0 and 1 based on the given easing function.
|
/// between 0 and 1 based on the given easing function.
|
||||||
pub easing: Box<dyn Fn(f32) -> f32>,
|
pub easing: Rc<dyn Fn(f32) -> f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Animation {
|
impl Animation {
|
||||||
|
@ -25,7 +29,7 @@ impl Animation {
|
||||||
Self {
|
Self {
|
||||||
duration,
|
duration,
|
||||||
oneshot: true,
|
oneshot: true,
|
||||||
easing: Box::new(linear),
|
easing: Rc::new(linear),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +43,7 @@ impl Animation {
|
||||||
/// The easing function will take a time delta between 0 and 1 and return a new delta
|
/// The easing function will take a time delta between 0 and 1 and return a new delta
|
||||||
/// between 0 and 1
|
/// between 0 and 1
|
||||||
pub fn with_easing(mut self, easing: impl Fn(f32) -> f32 + 'static) -> Self {
|
pub fn with_easing(mut self, easing: impl Fn(f32) -> f32 + 'static) -> Self {
|
||||||
self.easing = Box::new(easing);
|
self.easing = Rc::new(easing);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue