Cpp: Add a self_weak to repeated components

The main struct has it, and sub-components should have it, too.
This commit is contained in:
Simon Hausmann 2020-11-18 12:00:30 +01:00
parent ba96e8570f
commit a2839e03c2
2 changed files with 13 additions and 0 deletions

View file

@ -566,6 +566,8 @@ public:
auto &c = inner->data[i]; auto &c = inner->data[i];
if (!c.ptr) { if (!c.ptr) {
c.ptr = { vtable::VRc<private_api::ComponentVTable, C>::make(parent) }; c.ptr = { vtable::VRc<private_api::ComponentVTable, C>::make(parent) };
const_cast<C *>(&**c.ptr)->self_weak =
vtable::VWeak<private_api::ComponentVTable, C>(*c.ptr);
} }
if (c.state == RepeaterInner::State::Dirty) { if (c.state == RepeaterInner::State::Dirty) {
(*c.ptr)->update_data(i, m->row_data(i)); (*c.ptr)->update_data(i, m->row_data(i));

View file

@ -827,6 +827,17 @@ fn generate_component(
}), }),
)); ));
} }
component_struct.members.push((
Access::Public,
Declaration::Var(Var {
ty: format!(
"vtable::VWeak<sixtyfps::private_api::ComponentVTable, {}>",
component_id
),
name: "self_weak".into(),
..Var::default()
}),
));
component_struct.members.push(( component_struct.members.push((
Access::Private, Access::Private,
Declaration::Var(Var { Declaration::Var(Var {