Fix a bunch more issue with PopupWindow

* Make sure that the compiler don't panic if the parent of a PopupWindow
   is optimized (by not optiizing such element)

 * Ensure that we can call popup.show() from within a deeper repeater

 * Ensure that the parent element of the popup is the right one in case of
   repeater (and not the node in the parent component)

This partially revert ad5991f8fa and
6c7a7aed0e because we must do the lower_popup
adter the repeater pass, because otherwise the parent element of the
created component for the PopupWindow might be wrong and it is not easy to
adjust (we would have to make Component::parent_element a RefCell or duplicate
it again.

Fixes #1132
This commit is contained in:
Olivier Goffart 2022-04-01 12:17:12 +02:00 committed by Olivier Goffart
parent a329f052ea
commit f8f61dc2b7
10 changed files with 62 additions and 35 deletions

View file

@ -2320,16 +2320,26 @@ fn compile_builtin_function_call(
if let [llr::Expression::NumberLiteral(popup_index), x, y, llr::Expression::PropertyReference(parent_ref)] =
arguments
{
let mut parent_ctx = ctx;
let mut component_access = "self".into();
if let llr::PropertyReference::InParent { level, .. } = parent_ref {
for _ in 0..level.get() {
component_access = format!("{}->parent", component_access);
parent_ctx = parent_ctx.parent.as_ref().unwrap().ctx;
}
};
let window = access_window_field(ctx);
let current_sub_component = ctx.current_sub_component.unwrap();
let current_sub_component = parent_ctx.current_sub_component.unwrap();
let popup_window_id =
ident(&current_sub_component.popup_windows[*popup_index as usize].root.name);
let parent_component = access_item_rc(parent_ref, ctx);
let x = compile_expression(x, ctx);
let y = compile_expression(y, ctx);
format!(
"{}.show_popup<{}>(self, {{ {}, {} }}, {{ {} }})",
window, popup_window_id, x, y, parent_component,
"{}.show_popup<{}>({}, {{ {}, {} }}, {{ {} }})",
window, popup_window_id, component_access, x, y, parent_component,
)
} else {
panic!("internal error: invalid args to ShowPopupWindow {:?}", arguments)

View file

@ -1886,7 +1886,16 @@ fn compile_builtin_function_call(
if let [Expression::NumberLiteral(popup_index), x, y, Expression::PropertyReference(parent_ref)] =
arguments
{
let current_sub_component = ctx.current_sub_component.unwrap();
let mut parent_ctx = ctx;
let mut component_access_tokens = quote!(_self);
if let llr::PropertyReference::InParent { level, .. } = parent_ref {
for _ in 0..level.get() {
component_access_tokens =
quote!(#component_access_tokens.parent.upgrade().unwrap().as_pin_ref());
parent_ctx = parent_ctx.parent.as_ref().unwrap().ctx;
}
}
let current_sub_component = parent_ctx.current_sub_component.unwrap();
let popup_window_id = inner_component_id(
&current_sub_component.popup_windows[*popup_index as usize].root,
);
@ -1896,7 +1905,7 @@ fn compile_builtin_function_call(
let window_tokens = access_window_field(ctx);
quote!(
#window_tokens.show_popup(
&VRc::into_dyn(#popup_window_id::new(_self.self_weak.get().unwrap().clone()).into()),
&VRc::into_dyn(#popup_window_id::new(#component_access_tokens.self_weak.get().unwrap().clone()).into()),
Point::new(#x as f32, #y as f32),
#parent_component
);