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);
|
slint_windowrc_set_component(&inner, &item_tree_rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Component, typename Parent, typename XGetter, typename YGetter>
|
template<typename Component, typename Parent, typename PosGetter>
|
||||||
void show_popup(const Parent *parent_component, XGetter x_getter, YGetter y_getter,
|
void show_popup(const Parent *parent_component, PosGetter pos, bool close_on_click,
|
||||||
bool close_on_click, cbindgen_private::ItemRc parent_item) const
|
cbindgen_private::ItemRc parent_item) const
|
||||||
{
|
{
|
||||||
auto popup = Component::create(parent_component);
|
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();
|
auto popup_dyn = popup.into_dyn();
|
||||||
cbindgen_private::slint_windowrc_show_popup(&inner, &popup_dyn, p, close_on_click,
|
cbindgen_private::slint_windowrc_show_popup(&inner, &popup_dyn, p, close_on_click,
|
||||||
&parent_item);
|
&parent_item);
|
||||||
|
|
|
||||||
|
|
@ -3323,20 +3323,16 @@ fn compile_builtin_function_call(
|
||||||
let popup_window_id =
|
let popup_window_id =
|
||||||
ident(&popup.item_tree.root.name);
|
ident(&popup.item_tree.root.name);
|
||||||
let parent_component = access_item_rc(parent_ref, ctx);
|
let parent_component = access_item_rc(parent_ref, ctx);
|
||||||
|
|
||||||
let popup_ctx = EvaluationContext::new_sub_component(
|
let popup_ctx = EvaluationContext::new_sub_component(
|
||||||
ctx.compilation_unit,
|
ctx.compilation_unit,
|
||||||
&popup.item_tree.root,
|
&popup.item_tree.root,
|
||||||
CppGeneratorContext { global_access: "self->globals".into(), conditional_includes: ctx.generator_state.conditional_includes },
|
CppGeneratorContext { global_access: "self->globals".into(), conditional_includes: ctx.generator_state.conditional_includes },
|
||||||
Some(ParentCtx::new(&ctx, None)),
|
Some(ParentCtx::new(&ctx, None)),
|
||||||
);
|
);
|
||||||
|
let position = compile_expression(&popup.position.borrow(), &popup_ctx);
|
||||||
let x = access_member(&popup.x_prop, &popup_ctx);
|
|
||||||
let y = access_member(&popup.y_prop, &popup_ctx);
|
|
||||||
|
|
||||||
let close_on_click = compile_expression(close_on_click, ctx);
|
let close_on_click = compile_expression(close_on_click, ctx);
|
||||||
format!(
|
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 {
|
} else {
|
||||||
panic!("internal error: invalid args to ShowPopupWindow {:?}", arguments)
|
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()) },
|
RustGeneratorContext { global_access: quote!(_self.globals.get().unwrap()) },
|
||||||
Some(ParentCtx::new(&ctx, None)),
|
Some(ParentCtx::new(&ctx, None)),
|
||||||
);
|
);
|
||||||
let x = primitive_property_value(
|
let position = compile_expression(&popup.position.borrow(), &popup_ctx);
|
||||||
&Type::LogicalLength,
|
|
||||||
access_member(&popup.x_prop, &popup_ctx),
|
|
||||||
);
|
|
||||||
let y = primitive_property_value(
|
|
||||||
&Type::LogicalLength,
|
|
||||||
access_member(&popup.y_prop, &popup_ctx),
|
|
||||||
);
|
|
||||||
|
|
||||||
let close_on_click = compile_expression(close_on_click, ctx);
|
let close_on_click = compile_expression(close_on_click, ctx);
|
||||||
let window_adapter_tokens = access_window_adapter_field(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 = #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);
|
let popup_instance_vrc = sp::VRc::map(popup_instance.clone(), |x| x);
|
||||||
#popup_window_id::user_init(popup_instance_vrc.clone());
|
#popup_window_id::user_init(popup_instance_vrc.clone());
|
||||||
let x = { let _self = popup_instance_vrc.as_pin_ref(); #x };
|
let position = { let _self = popup_instance_vrc.as_pin_ref(); #position };
|
||||||
let y = { let _self = popup_instance_vrc.as_pin_ref(); #y };
|
|
||||||
sp::WindowInner::from_pub(#window_adapter_tokens.window()).show_popup(
|
sp::WindowInner::from_pub(#window_adapter_tokens.window()).show_popup(
|
||||||
&sp::VRc::into_dyn({
|
&sp::VRc::into_dyn(popup_instance.into()),
|
||||||
popup_instance.into()
|
position,
|
||||||
}),
|
|
||||||
sp::Point::new(x as sp::Coord, y as sp::Coord),
|
|
||||||
#close_on_click,
|
#close_on_click,
|
||||||
#parent_component
|
#parent_component
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -271,8 +271,7 @@ pub struct SubComponent {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PopupWindow {
|
pub struct PopupWindow {
|
||||||
pub item_tree: ItemTree,
|
pub item_tree: ItemTree,
|
||||||
pub x_prop: PropertyReference,
|
pub position: MutExpression,
|
||||||
pub y_prop: PropertyReference,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[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,
|
name: &str,
|
||||||
it: impl IntoIterator<Item = (&'static str, Type, llr_Expression)>,
|
it: impl IntoIterator<Item = (&'static str, Type, llr_Expression)>,
|
||||||
) -> llr_Expression {
|
) -> llr_Expression {
|
||||||
|
|
|
||||||
|
|
@ -668,11 +668,16 @@ fn lower_popup_component(
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
llr_PopupWindow {
|
use super::Expression::PropertyReference as PR;
|
||||||
item_tree,
|
let position = super::lower_expression::make_struct(
|
||||||
x_prop: sc.mapping.map_property_reference(&popup.x, ctx.state),
|
"Point",
|
||||||
y_prop: sc.mapping.map_property_reference(&popup.y, ctx.state),
|
[
|
||||||
}
|
("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(
|
fn lower_global(
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,7 @@ pub fn count_property_use(root: &CompilationUnit) {
|
||||||
(),
|
(),
|
||||||
Some(ParentCtx::new(&ctx, None)),
|
Some(ParentCtx::new(&ctx, None)),
|
||||||
);
|
);
|
||||||
visit_property(&popup.x_prop, &popup_ctx);
|
popup.position.borrow().visit_recursive(&mut |e| visit_expression(e, &popup_ctx))
|
||||||
visit_property(&popup.y_prop, &popup_ctx);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue