Fix PopupWindow within repeater

* The LLR expect that the popup_window is actually contained in it's parent
   component popup_windows, otherwise the context is not correct.
 * There is no index property for a PopupWindow

Fixes #1113
This commit is contained in:
Olivier Goffart 2022-03-30 14:59:08 +02:00 committed by Olivier Goffart
parent 143167f82f
commit ad5991f8fa
4 changed files with 44 additions and 12 deletions

View file

@ -530,9 +530,7 @@ fn generate_sub_component(
let mut extra_components = component
.popup_windows
.iter()
.map(|c| {
generate_item_tree(c, root, Some(ParentCtx::new(&ctx, None)), quote!(), index_property)
})
.map(|c| generate_item_tree(c, root, Some(ParentCtx::new(&ctx, None)), quote!(), None))
.collect::<Vec<_>>();
let mut declared_property_vars = vec![];
@ -766,17 +764,15 @@ fn generate_sub_component(
let visibility =
core::ptr::eq(&root.item_tree.root as *const _, component as *const _).then(|| quote!(pub));
let access_prop = |&property_index| {
access_member(
let subtree_index_function = if let Some(property_index) = index_property {
let prop = access_member(
&llr::PropertyReference::Local { sub_component_path: vec![], property_index },
&ctx,
)
);
quote!(#prop.get() as usize)
} else {
quote!(core::usize::MAX)
};
let prop = index_property.iter().map(access_prop);
let mut subtree_index_function = quote!(#(#prop.get() as usize)*);
if subtree_index_function.is_empty() {
subtree_index_function = quote!(core::usize::MAX);
}
quote!(
#[derive(slint::re_exports::FieldOffsets, Default)]

View file

@ -173,7 +173,7 @@ impl Document {
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct PopupWindow {
pub component: Rc<Component>,
pub x: NamedReference,

View file

@ -14,6 +14,7 @@ use std::rc::Rc;
pub fn process_repeater_components(component: &Rc<Component>) {
create_repeater_components(component);
adjust_references(component);
adjust_popups(component);
}
fn create_repeater_components(component: &Rc<Component>) {
@ -113,3 +114,22 @@ fn adjust_references(comp: &Rc<Component>) {
})
});
}
fn adjust_popups(component: &Rc<Component>) {
component.popup_windows.borrow_mut().retain(|popup| {
let parent = popup
.component
.parent_element
.upgrade()
.unwrap()
.borrow()
.enclosing_component
.upgrade()
.unwrap();
if Rc::ptr_eq(&parent, component) {
return true;
}
parent.popup_windows.borrow_mut().push(popup.clone());
false
});
}

View file

@ -0,0 +1,16 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
App := Window {
for menu-item in [{children: ["hello"]}] : VerticalLayout {
Rectangle {
popup := PopupWindow {
Rectangle {
for child in menu-item.children : Rectangle {
}
}
}
}
}
}