ferroui_base/rendering/composition/interactions/
interaction_tracker_inertia_modifier.rs1use crate::rendering::composition::animations::ExpressionAnimation;
5use crate::rendering::composition::Compositor;
6use std::cell::RefCell;
7use std::rc::Rc;
8
9#[derive(Clone)]
23pub enum InteractionTrackerInertiaModifier {
24 RestingValue(Rc<InteractionTrackerInertiaRestingValue>),
26 Motion(Rc<InteractionTrackerInertiaMotion>),
28}
29
30impl InteractionTrackerInertiaModifier {
31 pub fn condition(&self) -> Option<Rc<ExpressionAnimation>> {
33 match self {
34 Self::RestingValue(modifier) => modifier.condition(),
35 Self::Motion(modifier) => modifier.condition(),
36 }
37 }
38}
39
40impl From<Rc<InteractionTrackerInertiaRestingValue>> for InteractionTrackerInertiaModifier {
41 fn from(value: Rc<InteractionTrackerInertiaRestingValue>) -> Self {
42 Self::RestingValue(value)
43 }
44}
45
46impl From<Rc<InteractionTrackerInertiaMotion>> for InteractionTrackerInertiaModifier {
47 fn from(value: Rc<InteractionTrackerInertiaMotion>) -> Self {
48 Self::Motion(value)
49 }
50}
51
52pub struct InteractionTrackerInertiaRestingValue {
60 compositor: Rc<Compositor>,
61 condition: RefCell<Option<Rc<ExpressionAnimation>>>,
62 resting_value: RefCell<Option<Rc<ExpressionAnimation>>>,
63}
64
65impl InteractionTrackerInertiaRestingValue {
66 pub fn create(compositor: &Rc<Compositor>) -> Rc<InteractionTrackerInertiaRestingValue> {
68 Rc::new(InteractionTrackerInertiaRestingValue {
69 compositor: compositor.clone(),
70 condition: RefCell::new(None),
71 resting_value: RefCell::new(None),
72 })
73 }
74
75 pub fn compositor(&self) -> &Rc<Compositor> {
77 &self.compositor
78 }
79
80 pub fn condition(&self) -> Option<Rc<ExpressionAnimation>> {
83 self.condition.borrow().clone()
84 }
85
86 pub fn set_condition(&self, value: Option<Rc<ExpressionAnimation>>) {
87 *self.condition.borrow_mut() = value;
88 }
89
90 pub fn resting_value(&self) -> Option<Rc<ExpressionAnimation>> {
93 self.resting_value.borrow().clone()
94 }
95
96 pub fn set_resting_value(&self, value: Option<Rc<ExpressionAnimation>>) {
97 *self.resting_value.borrow_mut() = value;
98 }
99}
100
101pub struct InteractionTrackerInertiaMotion {
110 compositor: Rc<Compositor>,
111 condition: RefCell<Option<Rc<ExpressionAnimation>>>,
112 motion: RefCell<Option<Rc<ExpressionAnimation>>>,
113}
114
115impl InteractionTrackerInertiaMotion {
116 pub fn create(compositor: &Rc<Compositor>) -> Rc<InteractionTrackerInertiaMotion> {
118 Rc::new(InteractionTrackerInertiaMotion {
119 compositor: compositor.clone(),
120 condition: RefCell::new(None),
121 motion: RefCell::new(None),
122 })
123 }
124
125 pub fn compositor(&self) -> &Rc<Compositor> {
127 &self.compositor
128 }
129
130 pub fn condition(&self) -> Option<Rc<ExpressionAnimation>> {
133 self.condition.borrow().clone()
134 }
135
136 pub fn set_condition(&self, value: Option<Rc<ExpressionAnimation>>) {
137 *self.condition.borrow_mut() = value;
138 }
139
140 pub fn motion(&self) -> Option<Rc<ExpressionAnimation>> {
142 self.motion.borrow().clone()
143 }
144
145 pub fn set_motion(&self, value: Option<Rc<ExpressionAnimation>>) {
146 *self.motion.borrow_mut() = value;
147 }
148}