Implement property animations for C++

This commit is contained in:
Simon Hausmann 2020-06-25 13:32:50 +02:00
parent f50a705e00
commit e6b386ab53
4 changed files with 241 additions and 32 deletions

View file

@ -1,5 +1,12 @@
#pragma once
#include <string_view>
namespace sixtyfps {
namespace internal {
struct PropertyAnimation;
}
}
#include "sixtyfps_properties_internal.h"
namespace sixtyfps {
@ -41,8 +48,56 @@ struct Property
new F(binding), [](void *user_data) { delete reinterpret_cast<F *>(user_data); });
}
inline void set_animated_value(const T &value,
const internal::PropertyAnimation &animation_data);
template<typename F>
inline void set_animated_binding(F binding, const internal::PropertyAnimation &animation_data);
private:
internal::PropertyHandleOpaque inner;
mutable T value{};
};
template<>
void Property<int32_t>::set_animated_value(const int32_t &value,
const internal::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_value_int(&inner, value, &animation_data);
}
template<>
void Property<float>::set_animated_value(const float &value,
const internal::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_value_float(&inner, value, &animation_data);
}
template<>
template<typename F>
void Property<int32_t>::set_animated_binding(F binding,
const internal::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_binding_int(
&inner,
[](void *user_data, const internal::EvaluationContext *context, int32_t *value) {
*reinterpret_cast<int32_t *>(value) = (*reinterpret_cast<F *>(user_data))(context);
},
new F(binding), [](void *user_data) { delete reinterpret_cast<F *>(user_data); },
&animation_data);
}
template<>
template<typename F>
void Property<float>::set_animated_binding(F binding,
const internal::PropertyAnimation &animation_data)
{
internal::sixtyfps_property_set_animated_binding_float(
&inner,
[](void *user_data, const internal::EvaluationContext *context, float *value) {
*reinterpret_cast<float *>(value) = (*reinterpret_cast<F *>(user_data))(context);
},
new F(binding), [](void *user_data) { delete reinterpret_cast<F *>(user_data); },
&animation_data);
}
}