mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Interpreter: make sure that the properties are initialized in the right order
This commit is contained in:
parent
a79a4351b5
commit
ff368db505
1 changed files with 144 additions and 153 deletions
|
@ -12,12 +12,11 @@ use crate::{api::Value, dynamic_type, eval};
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use core::ptr::NonNull;
|
use core::ptr::NonNull;
|
||||||
use dynamic_type::{Instance, InstanceBox};
|
use dynamic_type::{Instance, InstanceBox};
|
||||||
use expression_tree::NamedReference;
|
use sixtyfps_compilerlib::expression_tree::{Expression, NamedReference};
|
||||||
use object_tree::{Element, ElementRc};
|
|
||||||
use sixtyfps_compilerlib::langtype::Type;
|
use sixtyfps_compilerlib::langtype::Type;
|
||||||
|
use sixtyfps_compilerlib::object_tree::{Element, ElementRc};
|
||||||
use sixtyfps_compilerlib::*;
|
use sixtyfps_compilerlib::*;
|
||||||
use sixtyfps_compilerlib::{diagnostics::BuildDiagnostics, object_tree::PropertyDeclaration};
|
use sixtyfps_compilerlib::{diagnostics::BuildDiagnostics, object_tree::PropertyDeclaration};
|
||||||
use sixtyfps_compilerlib::{expression_tree::Expression, langtype::PropertyLookupResult};
|
|
||||||
use sixtyfps_corelib::component::{Component, ComponentRef, ComponentRefPin, ComponentVTable};
|
use sixtyfps_corelib::component::{Component, ComponentRef, ComponentRefPin, ComponentVTable};
|
||||||
use sixtyfps_corelib::graphics::ImageReference;
|
use sixtyfps_corelib::graphics::ImageReference;
|
||||||
use sixtyfps_corelib::item_tree::{
|
use sixtyfps_corelib::item_tree::{
|
||||||
|
@ -898,38 +897,35 @@ pub fn instantiate<'id>(
|
||||||
&eval::window_ref(instance_ref).unwrap(),
|
&eval::window_ref(instance_ref).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
for item_within_component in component_type.items.values() {
|
generator::handle_property_bindings_init(
|
||||||
unsafe {
|
&component_type.original,
|
||||||
|
|elem, prop_name, binding| unsafe {
|
||||||
|
let elem = elem.borrow();
|
||||||
|
let item_within_component = &component_type.items[&elem.id];
|
||||||
let item = item_within_component.item_from_component(instance_ref.as_ptr());
|
let item = item_within_component.item_from_component(instance_ref.as_ptr());
|
||||||
let elem = item_within_component.elem.borrow();
|
|
||||||
for (unresolved_prop_name, expr) in &elem.bindings {
|
let property_type = elem.lookup_property(prop_name).property_type;
|
||||||
let PropertyLookupResult { resolved_name, property_type } =
|
|
||||||
elem.lookup_property(unresolved_prop_name.as_str());
|
|
||||||
if let Type::Callback { .. } = property_type {
|
if let Type::Callback { .. } = property_type {
|
||||||
let expr = expr.clone();
|
let expr = binding.expression.clone();
|
||||||
let component_type = component_type.clone();
|
let component_type = component_type.clone();
|
||||||
let instance = component_box.instance.as_ptr();
|
let instance = component_box.instance.as_ptr();
|
||||||
let c = Pin::new_unchecked(vtable::VRef::from_raw(
|
let c = Pin::new_unchecked(vtable::VRef::from_raw(
|
||||||
NonNull::from(&component_type.ct).cast(),
|
NonNull::from(&component_type.ct).cast(),
|
||||||
instance.cast(),
|
instance.cast(),
|
||||||
));
|
));
|
||||||
if let Some(callback) =
|
if let Some(callback) = item_within_component.rtti.callbacks.get(prop_name) {
|
||||||
item_within_component.rtti.callbacks.get(resolved_name.as_ref())
|
|
||||||
{
|
|
||||||
callback.set_handler(
|
callback.set_handler(
|
||||||
item,
|
item,
|
||||||
Box::new(move |args| {
|
Box::new(move |args| {
|
||||||
generativity::make_guard!(guard);
|
generativity::make_guard!(guard);
|
||||||
let mut local_context =
|
let mut local_context = eval::EvalLocalContext::from_function_arguments(
|
||||||
eval::EvalLocalContext::from_function_arguments(
|
|
||||||
InstanceRef::from_pin_ref(c, guard),
|
InstanceRef::from_pin_ref(c, guard),
|
||||||
args.iter().cloned().collect(),
|
args.iter().cloned().collect(),
|
||||||
);
|
);
|
||||||
eval::eval_expression(&expr, &mut local_context)
|
eval::eval_expression(&expr, &mut local_context)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
} else if let Some(callback_offset) =
|
} else if let Some(callback_offset) = component_type.custom_callbacks.get(prop_name)
|
||||||
component_type.custom_callbacks.get(resolved_name.as_ref())
|
|
||||||
{
|
{
|
||||||
let callback = callback_offset.apply(instance_ref.as_ref());
|
let callback = callback_offset.apply(instance_ref.as_ref());
|
||||||
callback.set_handler(move |args| {
|
callback.set_handler(move |args| {
|
||||||
|
@ -941,22 +937,21 @@ pub fn instantiate<'id>(
|
||||||
eval::eval_expression(&expr, &mut local_context)
|
eval::eval_expression(&expr, &mut local_context)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
panic!("unkown callback {}", unresolved_prop_name)
|
panic!("unkown callback {}", prop_name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(prop_rtti) =
|
if let Some(prop_rtti) = item_within_component.rtti.properties.get(prop_name) {
|
||||||
item_within_component.rtti.properties.get(resolved_name.as_ref())
|
let maybe_animation = animation_for_property(instance_ref, &elem, prop_name);
|
||||||
{
|
let mut e = Some(&binding.expression);
|
||||||
let maybe_animation =
|
|
||||||
animation_for_property(instance_ref, &elem, resolved_name.as_ref());
|
|
||||||
let mut e = Some(&expr.expression);
|
|
||||||
while let Some(Expression::TwoWayBinding(nr, next)) = &e {
|
while let Some(Expression::TwoWayBinding(nr, next)) = &e {
|
||||||
// Safety: The compiler must have ensured that the properties exist and are of the same type
|
// Safety: The compiler must have ensured that the properties exist and are of the same type
|
||||||
prop_rtti.link_two_ways(item, get_property_ptr(&nr, instance_ref));
|
prop_rtti.link_two_ways(item, get_property_ptr(&nr, instance_ref));
|
||||||
e = next.as_deref();
|
e = next.as_deref();
|
||||||
}
|
}
|
||||||
if let Some(e) = e {
|
if let Some(e) = e {
|
||||||
if e.is_constant() {
|
if binding.analysis.borrow().as_ref().map_or(false, |a| a.is_const)
|
||||||
|
|| e.is_constant()
|
||||||
|
{
|
||||||
prop_rtti.set(
|
prop_rtti.set(
|
||||||
item,
|
item,
|
||||||
eval::eval_expression(
|
eval::eval_expression(
|
||||||
|
@ -991,9 +986,8 @@ pub fn instantiate<'id>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(PropertiesWithinComponent {
|
} else if let Some(PropertiesWithinComponent { offset, prop: prop_info, .. }) =
|
||||||
offset, prop: prop_info, ..
|
component_type.custom_properties.get(prop_name)
|
||||||
}) = component_type.custom_properties.get(resolved_name.as_ref())
|
|
||||||
{
|
{
|
||||||
let c = Pin::new_unchecked(vtable::VRef::from_raw(
|
let c = Pin::new_unchecked(vtable::VRef::from_raw(
|
||||||
NonNull::from(&component_type.ct).cast(),
|
NonNull::from(&component_type.ct).cast(),
|
||||||
|
@ -1001,9 +995,7 @@ pub fn instantiate<'id>(
|
||||||
));
|
));
|
||||||
|
|
||||||
let is_state_info = match property_type {
|
let is_state_info = match property_type {
|
||||||
Type::Struct { name: Some(name), .. }
|
Type::Struct { name: Some(name), .. } if name.ends_with("::StateInfo") => {
|
||||||
if name.ends_with("::StateInfo") =>
|
|
||||||
{
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -1013,7 +1005,7 @@ pub fn instantiate<'id>(
|
||||||
&*(instance_ref.as_ptr().add(*offset)
|
&*(instance_ref.as_ptr().add(*offset)
|
||||||
as *const Property<sixtyfps_corelib::properties::StateInfo>),
|
as *const Property<sixtyfps_corelib::properties::StateInfo>),
|
||||||
);
|
);
|
||||||
let e = expr.expression.clone();
|
let e = binding.expression.clone();
|
||||||
sixtyfps_corelib::properties::set_state_binding(prop, move || {
|
sixtyfps_corelib::properties::set_state_binding(prop, move || {
|
||||||
generativity::make_guard!(guard);
|
generativity::make_guard!(guard);
|
||||||
eval::eval_expression(
|
eval::eval_expression(
|
||||||
|
@ -1025,17 +1017,17 @@ pub fn instantiate<'id>(
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
});
|
});
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let maybe_animation = animation_for_property(
|
let maybe_animation = animation_for_property(
|
||||||
instance_ref,
|
instance_ref,
|
||||||
&component_type.original.root_element.borrow(),
|
&component_type.original.root_element.borrow(),
|
||||||
resolved_name.as_ref(),
|
prop_name,
|
||||||
);
|
);
|
||||||
let item = Pin::new_unchecked(&*instance_ref.as_ptr().add(*offset));
|
let item = Pin::new_unchecked(&*instance_ref.as_ptr().add(*offset));
|
||||||
|
|
||||||
let mut e = Some(&expr.expression);
|
let mut e = Some(&binding.expression);
|
||||||
while let Some(Expression::TwoWayBinding(nr, next)) = &e {
|
while let Some(Expression::TwoWayBinding(nr, next)) = &e {
|
||||||
// Safety: The compiler must have ensured that the properties exist and are of the same type
|
// Safety: The compiler must have ensured that the properties exist and are of the same type
|
||||||
prop_info.link_two_ways(item, get_property_ptr(&nr, instance_ref));
|
prop_info.link_two_ways(item, get_property_ptr(&nr, instance_ref));
|
||||||
|
@ -1045,9 +1037,7 @@ pub fn instantiate<'id>(
|
||||||
if e.is_constant() {
|
if e.is_constant() {
|
||||||
let v = eval::eval_expression(
|
let v = eval::eval_expression(
|
||||||
e,
|
e,
|
||||||
&mut eval::EvalLocalContext::from_component_instance(
|
&mut eval::EvalLocalContext::from_component_instance(instance_ref),
|
||||||
instance_ref,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
prop_info.set(item, v, None).unwrap();
|
prop_info.set(item, v, None).unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1059,7 +1049,9 @@ pub fn instantiate<'id>(
|
||||||
generativity::make_guard!(guard);
|
generativity::make_guard!(guard);
|
||||||
eval::eval_expression(
|
eval::eval_expression(
|
||||||
&e,
|
&e,
|
||||||
&mut eval::EvalLocalContext::from_component_instance(InstanceRef::from_pin_ref(c, guard)),
|
&mut eval::EvalLocalContext::from_component_instance(
|
||||||
|
InstanceRef::from_pin_ref(c, guard),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
maybe_animation,
|
maybe_animation,
|
||||||
|
@ -1068,12 +1060,11 @@ pub fn instantiate<'id>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic!("unkown property {}", unresolved_prop_name);
|
panic!("unkown property {}", prop_name);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
for rep_in_comp in &component_type.repeater {
|
for rep_in_comp in &component_type.repeater {
|
||||||
generativity::make_guard!(guard);
|
generativity::make_guard!(guard);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue