mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
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:
parent
143167f82f
commit
ad5991f8fa
4 changed files with 44 additions and 12 deletions
|
@ -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)]
|
||||
|
|
|
@ -173,7 +173,7 @@ impl Document {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PopupWindow {
|
||||
pub component: Rc<Component>,
|
||||
pub x: NamedReference,
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
16
tests/cases/crashes/issue1113_popup_in_repeater.slint
Normal file
16
tests/cases/crashes/issue1113_popup_in_repeater.slint
Normal 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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue