mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 04:48:27 +00:00
LLR: merge the popup's x and y property access in one expression
This commit is contained in:
parent
821d8a893c
commit
e67e46ab47
7 changed files with 23 additions and 34 deletions
|
|
@ -105,12 +105,12 @@ public:
|
|||
slint_windowrc_set_component(&inner, &item_tree_rc);
|
||||
}
|
||||
|
||||
template<typename Component, typename Parent, typename XGetter, typename YGetter>
|
||||
void show_popup(const Parent *parent_component, XGetter x_getter, YGetter y_getter,
|
||||
bool close_on_click, cbindgen_private::ItemRc parent_item) const
|
||||
template<typename Component, typename Parent, typename PosGetter>
|
||||
void show_popup(const Parent *parent_component, PosGetter pos, bool close_on_click,
|
||||
cbindgen_private::ItemRc parent_item) const
|
||||
{
|
||||
auto popup = Component::create(parent_component);
|
||||
cbindgen_private::Point p { x_getter(popup), y_getter(popup) };
|
||||
cbindgen_private::Point p = pos(popup);
|
||||
auto popup_dyn = popup.into_dyn();
|
||||
cbindgen_private::slint_windowrc_show_popup(&inner, &popup_dyn, p, close_on_click,
|
||||
&parent_item);
|
||||
|
|
|
|||
|
|
@ -3323,20 +3323,16 @@ fn compile_builtin_function_call(
|
|||
let popup_window_id =
|
||||
ident(&popup.item_tree.root.name);
|
||||
let parent_component = access_item_rc(parent_ref, ctx);
|
||||
|
||||
let popup_ctx = EvaluationContext::new_sub_component(
|
||||
ctx.compilation_unit,
|
||||
&popup.item_tree.root,
|
||||
CppGeneratorContext { global_access: "self->globals".into(), conditional_includes: ctx.generator_state.conditional_includes },
|
||||
Some(ParentCtx::new(&ctx, None)),
|
||||
);
|
||||
|
||||
let x = access_member(&popup.x_prop, &popup_ctx);
|
||||
let y = access_member(&popup.y_prop, &popup_ctx);
|
||||
|
||||
let position = compile_expression(&popup.position.borrow(), &popup_ctx);
|
||||
let close_on_click = compile_expression(close_on_click, ctx);
|
||||
format!(
|
||||
"{window}.show_popup<{popup_window_id}>({component_access}, [=](auto self) {{ return {x}.get(); }}, [=](auto self) {{ return {y}.get(); }}, {close_on_click}, {{ {parent_component} }})"
|
||||
"{window}.show_popup<{popup_window_id}>({component_access}, [=](auto self) {{ return {position}; }}, {close_on_click}, {{ {parent_component} }})"
|
||||
)
|
||||
} else {
|
||||
panic!("internal error: invalid args to ShowPopupWindow {:?}", arguments)
|
||||
|
|
|
|||
|
|
@ -2475,14 +2475,7 @@ fn compile_builtin_function_call(
|
|||
RustGeneratorContext { global_access: quote!(_self.globals.get().unwrap()) },
|
||||
Some(ParentCtx::new(&ctx, None)),
|
||||
);
|
||||
let x = primitive_property_value(
|
||||
&Type::LogicalLength,
|
||||
access_member(&popup.x_prop, &popup_ctx),
|
||||
);
|
||||
let y = primitive_property_value(
|
||||
&Type::LogicalLength,
|
||||
access_member(&popup.y_prop, &popup_ctx),
|
||||
);
|
||||
let position = compile_expression(&popup.position.borrow(), &popup_ctx);
|
||||
|
||||
let close_on_click = compile_expression(close_on_click, ctx);
|
||||
let window_adapter_tokens = access_window_adapter_field(ctx);
|
||||
|
|
@ -2490,13 +2483,10 @@ fn compile_builtin_function_call(
|
|||
let popup_instance = #popup_window_id::new(#component_access_tokens.self_weak.get().unwrap().clone()).unwrap();
|
||||
let popup_instance_vrc = sp::VRc::map(popup_instance.clone(), |x| x);
|
||||
#popup_window_id::user_init(popup_instance_vrc.clone());
|
||||
let x = { let _self = popup_instance_vrc.as_pin_ref(); #x };
|
||||
let y = { let _self = popup_instance_vrc.as_pin_ref(); #y };
|
||||
let position = { let _self = popup_instance_vrc.as_pin_ref(); #position };
|
||||
sp::WindowInner::from_pub(#window_adapter_tokens.window()).show_popup(
|
||||
&sp::VRc::into_dyn({
|
||||
popup_instance.into()
|
||||
}),
|
||||
sp::Point::new(x as sp::Coord, y as sp::Coord),
|
||||
&sp::VRc::into_dyn(popup_instance.into()),
|
||||
position,
|
||||
#close_on_click,
|
||||
#parent_component
|
||||
)
|
||||
|
|
|
|||
|
|
@ -271,8 +271,7 @@ pub struct SubComponent {
|
|||
#[derive(Debug)]
|
||||
pub struct PopupWindow {
|
||||
pub item_tree: ItemTree,
|
||||
pub x_prop: PropertyReference,
|
||||
pub y_prop: PropertyReference,
|
||||
pub position: MutExpression,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -975,7 +975,7 @@ fn compile_path(path: &crate::expression_tree::Path, ctx: &ExpressionContext) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn make_struct(
|
||||
pub fn make_struct(
|
||||
name: &str,
|
||||
it: impl IntoIterator<Item = (&'static str, Type, llr_Expression)>,
|
||||
) -> llr_Expression {
|
||||
|
|
|
|||
|
|
@ -668,11 +668,16 @@ fn lower_popup_component(
|
|||
),
|
||||
};
|
||||
|
||||
llr_PopupWindow {
|
||||
item_tree,
|
||||
x_prop: sc.mapping.map_property_reference(&popup.x, ctx.state),
|
||||
y_prop: sc.mapping.map_property_reference(&popup.y, ctx.state),
|
||||
}
|
||||
use super::Expression::PropertyReference as PR;
|
||||
let position = super::lower_expression::make_struct(
|
||||
"Point",
|
||||
[
|
||||
("x", Type::LogicalLength, PR(sc.mapping.map_property_reference(&popup.x, ctx.state))),
|
||||
("y", Type::LogicalLength, PR(sc.mapping.map_property_reference(&popup.y, ctx.state))),
|
||||
],
|
||||
);
|
||||
|
||||
llr_PopupWindow { item_tree, position: position.into() }
|
||||
}
|
||||
|
||||
fn lower_global(
|
||||
|
|
|
|||
|
|
@ -127,8 +127,7 @@ pub fn count_property_use(root: &CompilationUnit) {
|
|||
(),
|
||||
Some(ParentCtx::new(&ctx, None)),
|
||||
);
|
||||
visit_property(&popup.x_prop, &popup_ctx);
|
||||
visit_property(&popup.y_prop, &popup_ctx);
|
||||
popup.position.borrow().visit_recursive(&mut |e| visit_expression(e, &popup_ctx))
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue