This commit is contained in:
Olivier Goffart 2020-05-20 09:34:14 +02:00
parent 6b3765857a
commit bf64e40476
4 changed files with 23 additions and 31 deletions

View file

@ -9,8 +9,8 @@ struct ComponentVTable;
namespace sixtyfps { namespace sixtyfps {
// Bring opaque structure in scope // Bring opaque structure in scope
using internal::ItemTreeNode;
using internal::ComponentVTable; using internal::ComponentVTable;
using internal::ItemTreeNode;
using ComponentRef = VRefMut<ComponentVTable>; using ComponentRef = VRefMut<ComponentVTable>;
template<typename Component> template<typename Component>
@ -32,7 +32,6 @@ using internal::TextVTable;
using internal::TouchArea; using internal::TouchArea;
using internal::TouchAreaVTable; using internal::TouchAreaVTable;
// the component has static lifetime so it does not need to be destroyed // the component has static lifetime so it does not need to be destroyed
// FIXME: we probably need some kind of way to dinstinguish static component and // FIXME: we probably need some kind of way to dinstinguish static component and
// these on the heap // these on the heap

View file

@ -7,42 +7,35 @@ namespace sixtyfps {
template<typename T> template<typename T>
struct Property struct Property
{ {
Property() { Property() { internal::sixtyfps_property_init(&inner); }
internal::sixtyfps_property_init(&inner); ~Property() { internal::sixtyfps_property_drop(&inner); }
} Property(const Property &) = delete;
~Property() { Property(Property &&) = delete;
internal::sixtyfps_property_drop(&inner); Property &operator=(const Property &) = delete;
}
Property(const Property&) = delete;
Property(Property&&) = delete;
Property &operator=(const Property&) = delete;
/* Should it be implicit? /* Should it be implicit?
void operator=(const T &value) { void operator=(const T &value) {
set(value); set(value);
}*/ }*/
void set(const T &value) const { void set(const T &value) const { this->value = value; }
this->value = value;
}
const T &get() const { const T &get() const
{
internal::sixtyfps_property_update(&inner, &value); internal::sixtyfps_property_update(&inner, &value);
return value; return value;
} }
template <typename F> template<typename F>
void set_binding(F binding) const { void set_binding(F binding) const
{
internal::sixtyfps_property_set_binding( internal::sixtyfps_property_set_binding(
&inner, &inner,
[](const void *user_data, const void *value) { [](const void *user_data, const void *value) {
*reinterpret_cast<T*>(value) = (*reinterpret_cast<F*>(user_data))(); *reinterpret_cast<T *>(value) = (*reinterpret_cast<F *>(user_data))();
}, },
new F(binding), new F(binding),
[](const void *user_data) { [](const void *user_data) { delete reinterpret_cast<F *>(user_data); });
delete reinterpret_cast<F*>(user_data);
}
);
} }
private: private:

View file

@ -127,7 +127,6 @@ impl ItemConsts for Text {
#[no_mangle] #[no_mangle]
pub static TextVTable: ItemVTable = Text::VTABLE; pub static TextVTable: ItemVTable = Text::VTABLE;
#[repr(C)] #[repr(C)]
#[derive(const_field_offset::FieldOffsets, Default)] #[derive(const_field_offset::FieldOffsets, Default)]
pub struct TouchArea { pub struct TouchArea {
@ -153,8 +152,10 @@ impl Item for TouchArea {
} }
impl ItemConsts for TouchArea { impl ItemConsts for TouchArea {
const cached_rendering_data_offset: const_field_offset::FieldOffset<TouchArea, CachedRenderingData> = const cached_rendering_data_offset: const_field_offset::FieldOffset<
TouchArea::field_offsets().cached_rendering_data; TouchArea,
CachedRenderingData,
> = TouchArea::field_offsets().cached_rendering_data;
} }
#[no_mangle] #[no_mangle]

View file

@ -176,7 +176,6 @@ fn main() -> std::io::Result<()> {
}, },
); );
let l = lower::LoweredComponent::lower(&*tree.root_component); let l = lower::LoweredComponent::lower(&*tree.root_component);
let mut tree_array = vec![]; let mut tree_array = vec![];