mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 13:51:13 +00:00
Change the representation of the Property to be more FFI friendly
This commit is contained in:
parent
cdeb3a4312
commit
8ec6fd5237
6 changed files with 258 additions and 72 deletions
51
api/sixtyfps-cpp/include/sixtyfps_properties.h
Normal file
51
api/sixtyfps-cpp/include/sixtyfps_properties.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#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;
|
||||
|
||||
void operator=(const T &value) {
|
||||
set(value);
|
||||
}
|
||||
|
||||
void set(const T &value) const {
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
const T &get() const {
|
||||
internal::sixtyfps_property_update(&inner, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void set_binding(F binding) const {
|
||||
internal::sixtyfps_property_set_binding(
|
||||
&inner,
|
||||
[](const void *user_data, const void *value) {
|
||||
*reinterpret_cast<T*>(value) = (*reinterpret_cast<F*>(user_data))();
|
||||
},
|
||||
new F(binding),
|
||||
[](const void *user_data) {
|
||||
delete reinterpret_cast<F*>(user_data);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
internal::PropertyHandleOpaque inner;
|
||||
mutable T value;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue