Property refactoring

The tests are working and everything seems to be back normal.
But there is still some cleanup required
This commit is contained in:
Olivier Goffart 2020-07-01 18:46:33 +02:00
parent facc18d0eb
commit 9d852f802e
7 changed files with 716 additions and 486 deletions

View file

@ -32,10 +32,10 @@ private:
};
template<>
void Property<Color>::set_animated_value(const Color &value,
void Property<Color>::set_animated_value(const Color &new_value,
const internal::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_value_color(&inner, &value, &animation_data);
internal::sixtyfps_property_set_animated_value_color(&inner, value, new_value, &animation_data);
}
template<>

View file

@ -59,17 +59,17 @@ private:
};
template<>
void Property<int32_t>::set_animated_value(const int32_t &value,
void Property<int32_t>::set_animated_value(const int32_t &new_value,
const internal::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_value_int(&inner, value, &animation_data);
internal::sixtyfps_property_set_animated_value_int(&inner, value, new_value, &animation_data);
}
template<>
void Property<float>::set_animated_value(const float &value,
void Property<float>::set_animated_value(const float &new_value,
const internal::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_value_float(&inner, value, &animation_data);
internal::sixtyfps_property_set_animated_value_float(&inner, value, new_value, &animation_data);
}
template<>

View file

@ -32,3 +32,6 @@ instant = { version = "0.1", features = [ "wasm-bindgen", "now" ] }
[build-dependencies]
cbindgen = "0.14.2"
[dev-dependencies]
weak-pin = { path = "../../helper_crates/weak-pin" }

File diff suppressed because it is too large Load diff

View file

@ -91,13 +91,26 @@ enum InternalAnimationState {
}
/// The AnimationDriver
#[derive(Default)]
pub struct AnimationDriver {
animations: Vec<InternalAnimationEntry>,
next_free: Option<usize>,
len: usize,
/// Indicate whether there are any active animations that require a future call to update_animations.
active_animations: Cell<bool>,
global_instant: core::pin::Pin<Box<crate::Property<instant::Instant>>>,
}
impl Default for AnimationDriver {
fn default() -> Self {
AnimationDriver {
animations: vec![],
next_free: None,
len: 0,
active_animations: Cell::default(),
global_instant: Box::pin(crate::Property::new(instant::Instant::now())),
}
}
}
/// The AnimationHandle can be used to refer to an animation after it's been started, in order to
@ -112,6 +125,7 @@ impl AnimationDriver {
self.active_animations.set(false);
let mut need_new_animation_frame = false;
let mut i: usize = 0;
self.global_instant.as_ref().set(new_tick);
while i < self.animations.len() {
{
let animation = match &self.animations[i] {
@ -179,6 +193,11 @@ impl AnimationDriver {
self.active_animations.get()
}
/// Tell the driver that there are active animations
pub fn set_has_active_animations(&self) {
self.active_animations.set(true);
}
/// Start a new animation and returns a handle for it.
pub fn start_animation(&mut self, animation_callback: Weak<dyn Animated>) -> AnimationHandle {
let animation = InternalAnimation::new(animation_callback);
@ -265,9 +284,25 @@ impl AnimationDriver {
let anim = self.animations[index].as_animation();
anim.borrow_mut().state = new_state;
}
/// The current instant that is to be used for animation
/// using this function register the current binding as a dependency
pub fn current_tick(&self) -> instant::Instant {
// FIXME! we need to get rid of the contect there
#[allow(unsafe_code)]
let dummy_eval_context = crate::EvaluationContext::for_root_component(unsafe {
core::pin::Pin::new_unchecked(vtable::VRef::from_raw(
core::ptr::NonNull::dangling(),
core::ptr::NonNull::dangling(),
))
});
self.global_instant.as_ref().get(&dummy_eval_context)
}
}
thread_local!(pub(crate) static CURRENT_ANIMATION_DRIVER : Rc<RefCell<AnimationDriver>> = Default::default());
thread_local!(pub(crate) static CURRENT_ANIMATION_DRIVER : Rc<RefCell<AnimationDriver>> =
Default::default()
);
#[cfg(test)]
mod test {

View file

@ -83,6 +83,9 @@ impl EventLoop {
event: winit::event::WindowEvent::MouseInput { state, .. },
..
} => {
crate::animations::CURRENT_ANIMATION_DRIVER.with(|driver| {
driver.borrow_mut().update_animations(instant::Instant::now());
});
ALL_WINDOWS.with(|windows| {
if let Some(Some(window)) =
windows.borrow().get(&window_id).map(|weakref| weakref.upgrade())

View file

@ -15,6 +15,7 @@ pub mod graphics;
pub mod input;
pub mod item_tree;
pub mod layout;
//pub mod properties;
#[cfg(feature = "rtti")]
pub mod rtti;