ferroui_base/rendering/composition/
i_composition_object_host.rs1use super::animations::{AnimationInstanceFactory, ICompositionAnimationBase};
5use super::expressions::ExpressionVariant;
6use super::server::{CompositionProperty, ServerObjectId};
7use super::transport::IRegisterForSerialization;
8use std::any::Any;
9use std::cell::RefCell;
10use std::rc::Rc;
11
12pub trait ICompositionObject: 'static {
15 fn server(&self) -> ServerObjectId;
17
18 fn as_any(&self) -> &dyn Any;
19
20 fn into_any_rc(self: Rc<Self>) -> Rc<dyn Any>;
21}
22
23#[derive(Default)]
26pub struct PendingAnimations {
27 items: RefCell<Vec<(i32, AnimationInstanceFactory)>>,
28}
29
30impl PendingAnimations {
31 pub fn new() -> Self {
32 Self::default()
33 }
34
35 pub fn count(&self) -> usize {
36 self.items.borrow().len()
37 }
38
39 pub fn remove(&self, property: &CompositionProperty) -> bool {
42 self.get_and_remove(property).is_some()
43 }
44
45 pub fn set(&self, property: &CompositionProperty, animation: AnimationInstanceFactory) {
48 let mut items = self.items.borrow_mut();
49 match items.iter_mut().find(|(id, _)| *id == property.id()) {
50 Some(entry) => entry.1 = animation,
51 None => items.push((property.id(), animation)),
52 }
53 }
54
55 pub fn get_and_remove(&self, property: &CompositionProperty) -> Option<AnimationInstanceFactory> {
57 let mut items = self.items.borrow_mut();
58 let index = items.iter().position(|(id, _)| *id == property.id())?;
59 Some(items.remove(index).1)
60 }
61}
62
63pub trait ICompositionObjectHost: IRegisterForSerialization {
67 fn server(&self) -> ServerObjectId;
69
70 fn pending_animations(&self) -> &PendingAnimations;
72
73 fn implicit_animation(&self, property_name: &str) -> Option<Rc<dyn ICompositionAnimationBase>>;
76
77 fn start_animation_group(
81 &self,
82 grp: &Rc<dyn ICompositionAnimationBase>,
83 target: &str,
84 final_value: ExpressionVariant,
85 ) -> bool;
86}