Emit a warning to stderr (debug_log) when using the ElementHandle API but there's no debug info present

This commit is contained in:
Simon Hausmann 2024-06-03 15:19:16 +02:00 committed by Simon Hausmann
parent 622991a627
commit 15b517a554
5 changed files with 80 additions and 40 deletions

View file

@ -1410,10 +1410,10 @@ fn generate_item_tree(
Declaration::Function(Function {
name: "element_infos".into(),
signature:
"([[maybe_unused]] slint::private_api::ItemTreeRef component, uint32_t index, slint::SharedString *result) -> void"
"([[maybe_unused]] slint::private_api::ItemTreeRef component, uint32_t index, slint::SharedString *result) -> bool"
.into(),
is_static: true,
statements: Some(vec![format!("*result = reinterpret_cast<const {}*>(component.instance)->element_infos(index);", item_tree_class_name)]),
statements: Some(vec![format!("if (auto infos = reinterpret_cast<const {}*>(component.instance)->element_infos(index)) {{ *result = *infos; return true; }};", item_tree_class_name), "return false;".into()]),
..Default::default()
}),
));
@ -2044,7 +2044,7 @@ fn generate_sub_component(
dispatch_item_function(
"element_infos",
"(uint32_t index) const -> slint::SharedString",
"(uint32_t index) const -> std::optional<slint::SharedString>",
"",
element_infos_cases,
);

View file

@ -837,7 +837,7 @@ fn generate_sub_component(
let mut item_element_infos_branch = component
.element_infos
.iter()
.map(|(item_index, ids)| quote!(#item_index => { return #ids.into(); }))
.map(|(item_index, ids)| quote!(#item_index => { return sp::Some(#ids.into()); }))
.collect::<Vec<_>>();
let mut user_init_code: Vec<TokenStream> = Vec::new();
@ -1158,7 +1158,7 @@ fn generate_sub_component(
}
}
fn item_element_infos(self: ::core::pin::Pin<&Self>, index: u32) -> sp::SharedString {
fn item_element_infos(self: ::core::pin::Pin<&Self>, index: u32) -> sp::Option<sp::SharedString> {
#![allow(unused)]
let _self = self;
match index {
@ -1628,8 +1628,13 @@ fn generate_item_tree(
self: ::core::pin::Pin<&Self>,
index: u32,
result: &mut sp::SharedString,
) {
*result = self.item_element_infos(index);
) -> bool {
if let Some(infos) = self.item_element_infos(index) {
*result = infos;
true
} else {
false
}
}
fn window_adapter(