mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 18:29:09 +00:00
c++: Implement subtree_index(...)
This commit is contained in:
parent
0ca23948fb
commit
e05d24b2cf
1 changed files with 20 additions and 2 deletions
|
@ -966,13 +966,15 @@ fn generate_item_tree(
|
|||
}),
|
||||
));
|
||||
|
||||
// Statements will be overridden for repeated components!
|
||||
target_struct.members.push((
|
||||
Access::Private,
|
||||
Declaration::Function(Function {
|
||||
name: "subtree_index".into(),
|
||||
signature: "(slint::private_api::ComponentRef /* component */) -> uintptr_t".into(),
|
||||
signature: "([[maybe_unused]] slint::private_api::ComponentRef component) -> uintptr_t"
|
||||
.into(),
|
||||
is_static: true,
|
||||
statements: Some(vec!["/* unimplemented! */".to_owned(), "return 0;".into()]),
|
||||
statements: Some(vec![format!("return {};", std::usize::MAX)]),
|
||||
..Default::default()
|
||||
}),
|
||||
));
|
||||
|
@ -1584,6 +1586,22 @@ fn generate_repeated_component(
|
|||
));
|
||||
}
|
||||
|
||||
if let Some(index_prop) = repeated.index_prop {
|
||||
// Override default subtree_index function implementation
|
||||
let subtree_index_func = repeater_struct.members.iter_mut().find(|(_, d)| match d {
|
||||
Declaration::Function(f) if f.name == "subtree_index" => true,
|
||||
_ => false,
|
||||
});
|
||||
|
||||
if let Declaration::Function(f) = &mut subtree_index_func.unwrap().1 {
|
||||
let index = access_prop(&index_prop);
|
||||
f.statements = Some(vec![
|
||||
"[[maybe_unused]] auto self = this;".into(),
|
||||
format!("return {}.get();", index),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
file.definitions.extend(repeater_struct.extract_definitions().collect::<Vec<_>>());
|
||||
file.declarations.push(Declaration::Struct(repeater_struct));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue