Skip to content

Commit

Permalink
Fix PopupWindow within repeater
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
ogoffart committed Mar 30, 2022
1 parent 4fc45ed commit ef17480
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
18 changes: 7 additions & 11 deletions internal/compiler/generator/rust.rs
Expand Up @@ -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![];
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/object_tree.rs
Expand Up @@ -173,7 +173,7 @@ impl Document {
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct PopupWindow {
pub component: Rc<Component>,
pub x: NamedReference,
Expand Down
20 changes: 20 additions & 0 deletions internal/compiler/passes/repeater_component.rs
Expand Up @@ -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>) {
Expand Down Expand Up @@ -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 changes: 16 additions & 0 deletions tests/cases/crashes/issue1113_popup_in_repeater.slint
@@ -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 {
}
}
}
}
}
}

0 comments on commit ef17480

Please sign in to comment.