slint/api/sixtyfps-cpp/include/sixtyfps_properties.h
Simon Hausmann f2df9293a9 Fix the C++ build
Remove the Optional from the evaluation context passing for property
evaluation. Unfortunately there are nullptr uses left on the C++ side,
that need to be replaced with passing through.
2020-05-28 12:07:11 +02:00

45 lines
1.2 KiB
C++

#pragma once
#include <string_view>
#include "sixtyfps_properties_internal.h"
namespace sixtyfps {
template<typename T>
struct Property
{
Property() { internal::sixtyfps_property_init(&inner); }
~Property() { internal::sixtyfps_property_drop(&inner); }
Property(const Property &) = delete;
Property(Property &&) = delete;
Property &operator=(const Property &) = delete;
/* Should it be implicit?
void operator=(const T &value) {
set(value);
}*/
void set(const T &value) const { this->value = value; }
const T &get(internal::EvaluationContext *context) const
{
internal::sixtyfps_property_update(&inner, context, &value);
return value;
}
template<typename F>
void set_binding(F binding) const
{
internal::sixtyfps_property_set_binding(
&inner,
[](void *user_data, const void *value) {
*reinterpret_cast<T *>(value) = (*reinterpret_cast<F *>(user_data))();
},
new F(binding),
[](void *user_data) { delete reinterpret_cast<F *>(user_data); });
}
private:
internal::PropertyHandleOpaque inner;
mutable T value;
};
}