mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Make the parent_item function work with repeater component
This commit is contained in:
parent
7de0918f0d
commit
789ac719eb
2 changed files with 24 additions and 7 deletions
|
@ -142,6 +142,7 @@ public:
|
||||||
friend bool operator!=(const VRc &a, const VRc &b) {
|
friend bool operator!=(const VRc &a, const VRc &b) {
|
||||||
return a.inner != b.inner;
|
return a.inner != b.inner;
|
||||||
}
|
}
|
||||||
|
const VTable *vtable() const { return inner->vtable; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename VTable, typename X = Dyn>
|
template<typename VTable, typename X = Dyn>
|
||||||
|
@ -183,6 +184,7 @@ public:
|
||||||
friend bool operator!=(const VWeak &a, const VWeak &b) {
|
friend bool operator!=(const VWeak &a, const VWeak &b) {
|
||||||
return a.inner != b.inner;
|
return a.inner != b.inner;
|
||||||
}
|
}
|
||||||
|
const VTable *vtable() const { return inner ? inner->vtable : nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1207,7 +1207,7 @@ fn generate_component(
|
||||||
local_index = item.item_index.get().unwrap()
|
local_index = item.item_index.get().unwrap()
|
||||||
));
|
));
|
||||||
|
|
||||||
init.push(format!("{}.init();", member_name));
|
init.push(format!("{}.init(self_weak.into_dyn());", member_name));
|
||||||
|
|
||||||
component_struct.members.push((
|
component_struct.members.push((
|
||||||
field_access,
|
field_access,
|
||||||
|
@ -1291,9 +1291,6 @@ fn generate_component(
|
||||||
constructor_arguments =
|
constructor_arguments =
|
||||||
format!("{} root, [[maybe_unused]] uintptr_t item_index_start", root_ptr_type);
|
format!("{} root, [[maybe_unused]] uintptr_t item_index_start", root_ptr_type);
|
||||||
|
|
||||||
constructor_member_initializers.push("m_window(root->m_window.window_handle())".into());
|
|
||||||
constructor_member_initializers.push("m_root(root)".into());
|
|
||||||
|
|
||||||
component_struct.members.push((
|
component_struct.members.push((
|
||||||
Access::Private,
|
Access::Private,
|
||||||
Declaration::Var(Var {
|
Declaration::Var(Var {
|
||||||
|
@ -1302,6 +1299,7 @@ fn generate_component(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
constructor_member_initializers.push("m_window(root->m_window.window_handle())".into());
|
||||||
|
|
||||||
component_struct.members.push((
|
component_struct.members.push((
|
||||||
Access::Private,
|
Access::Private,
|
||||||
|
@ -1311,6 +1309,17 @@ fn generate_component(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
constructor_member_initializers.push("m_root(root)".into());
|
||||||
|
|
||||||
|
// self_weak is not really self in that case, it is a pointer to the enclosing component
|
||||||
|
component_struct.members.push((
|
||||||
|
Access::Private,
|
||||||
|
Declaration::Var(Var {
|
||||||
|
ty: "sixtyfps::cbindgen_private::ComponentWeak".into(),
|
||||||
|
name: "self_weak".into(),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
let root_element = component.root_element.borrow();
|
let root_element = component.root_element.borrow();
|
||||||
let get_root_item = if root_element.sub_component().is_some() {
|
let get_root_item = if root_element.sub_component().is_some() {
|
||||||
|
@ -1344,12 +1353,16 @@ fn generate_component(
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let mut init_statements = Vec::with_capacity(init.len() + 1);
|
||||||
|
init_statements.push("self_weak = enclosing_component;".to_string());
|
||||||
|
init_statements.append(&mut init);
|
||||||
|
|
||||||
component_struct.members.push((
|
component_struct.members.push((
|
||||||
Access::Public,
|
Access::Public,
|
||||||
Declaration::Function(Function {
|
Declaration::Function(Function {
|
||||||
name: "init".into(),
|
name: "init".into(),
|
||||||
signature: "()".into(),
|
signature: "(sixtyfps::cbindgen_private::ComponentWeak enclosing_component)".into(),
|
||||||
statements: Some(std::mem::take(&mut init)),
|
statements: Some(init_statements),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
|
@ -1477,7 +1490,9 @@ fn generate_component_vtable(
|
||||||
component.parent_element.upgrade().and_then(|e| e.borrow().item_index.get().copied())
|
component.parent_element.upgrade().and_then(|e| e.borrow().item_index.get().copied())
|
||||||
{
|
{
|
||||||
format!(
|
format!(
|
||||||
" *result = sixtyfps::private_api::parent_item(self->parent->self_weak.into_dyn(), self->parent->item_tree(), {});",
|
// that does not work when the parent is not a component with a ComponentVTable
|
||||||
|
//" *result = sixtyfps::private_api::parent_item(self->parent->self_weak.into_dyn(), self->parent->item_tree(), {});",
|
||||||
|
"self->parent->self_weak.vtable()->parent_item(self->parent->self_weak.lock()->borrow(), {}, result);",
|
||||||
parent_index,
|
parent_index,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue