Add support for manually closing PopupWindows

This patch adds a `close()` function that can be called to close a popup
window, and a `close-to-click` boolean that can be set to false to
disable the default behavior.
This commit is contained in:
Simon Hausmann 2023-06-02 08:12:39 +02:00 committed by Simon Hausmann
parent a0a5294e49
commit 0f54b9599b
20 changed files with 349 additions and 24 deletions

View file

@ -2233,7 +2233,7 @@ fn compile_builtin_function_call(
}
}
BuiltinFunction::ShowPopupWindow => {
if let [Expression::NumberLiteral(popup_index), x, y, Expression::PropertyReference(parent_ref)] =
if let [Expression::NumberLiteral(popup_index), x, y, close_on_click, Expression::PropertyReference(parent_ref)] =
arguments
{
let mut parent_ctx = ctx;
@ -2252,6 +2252,7 @@ fn compile_builtin_function_call(
let parent_component = access_item_rc(parent_ref, ctx);
let x = compile_expression(x, ctx);
let y = compile_expression(y, ctx);
let close_on_click = compile_expression(close_on_click, ctx);
let window_adapter_tokens = access_window_adapter_field(ctx);
quote!(
slint::private_unstable_api::re_exports::WindowInner::from_pub(#window_adapter_tokens.window()).show_popup(
@ -2261,6 +2262,7 @@ fn compile_builtin_function_call(
instance.into()
}),
Point::new(#x as slint::private_unstable_api::re_exports::Coord, #y as slint::private_unstable_api::re_exports::Coord),
#close_on_click,
#parent_component
)
)
@ -2268,6 +2270,12 @@ fn compile_builtin_function_call(
panic!("internal error: invalid args to ShowPopupWindow {:?}", arguments)
}
}
BuiltinFunction::ClosePopupWindow => {
let window_adapter_tokens = access_window_adapter_field(ctx);
quote!(
slint::private_unstable_api::re_exports::WindowInner::from_pub(#window_adapter_tokens.window()).close_popup()
)
}
BuiltinFunction::ItemMemberFunction(name) => {
if let [Expression::PropertyReference(pr)] = arguments {
let item = access_member(pr, ctx);