Skip to main content

ferroui_base/rendering/composition/animations/
i_composition_animation_base.rs

1use super::CompositionAnimationGroup;
2use crate::rendering::composition::expressions::ExpressionVariant;
3use crate::rendering::composition::server::ServerObjectId;
4
5/// Base class for composition animations.
6///
7/// What can be started on a composition object: a single animation
8/// ([`ICompositionAnimation`]) or a group of animations
9/// ([`CompositionAnimationGroup`]). Upstream the interface is closed to
10/// other implementations by an internal member; here the two accessors
11/// stand for the `is CompositionAnimation` and `is CompositionAnimationGroup`
12/// tests of upstream.
13pub trait ICompositionAnimationBase: 'static {
14    /// The animation when it is a single animation rather than a group.
15    fn as_composition_animation(&self) -> Option<&dyn ICompositionAnimation> {
16        None
17    }
18
19    /// The group when it is a group of animations.
20    fn as_composition_animation_group(&self) -> Option<&CompositionAnimationGroup> {
21        None
22    }
23}
24
25/// The members of `CompositionAnimation` that code outside the animation
26/// classes uses: the target property and the creation of the instance that
27/// runs on the server.
28///
29/// The animation classes implement it; `Rc<dyn ICompositionAnimation>` is
30/// the handle of upstream's abstract `CompositionAnimation`.
31pub trait ICompositionAnimation: ICompositionAnimationBase {
32    /// The name of the property the animation targets, if set.
33    fn target(&self) -> Option<String>;
34
35    /// Creates the server-side instance of the animation for a property of
36    /// `target_object`, as the factory that is sent to the server. `final_value` is the value the property was just
37    /// set to when the animation is implicit.
38    fn create_instance(
39        &self,
40        target_object: ServerObjectId,
41        final_value: Option<ExpressionVariant>,
42    ) -> super::AnimationInstanceFactory;
43}