Skip to content

Commit

Permalink
Fix another regression in layout due to non inlining
Browse files Browse the repository at this point in the history
override_from_parent.60 was panicking when compiling rust
because some expression had NamedReference that were relative to another
sub component.

Added a test as well for the case of multiple indirection (SubComp4)
that was also broken
  • Loading branch information
ogoffart committed Nov 24, 2021
1 parent 84e394a commit 06d1293
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
69 changes: 37 additions & 32 deletions sixtyfps_compiler/layout.rs
Expand Up @@ -492,44 +492,49 @@ pub fn layout_info_type() -> Type {

/// Get the implicit layout info of a particular element
pub fn implicit_layout_info_call(elem: &ElementRc, orientation: Orientation) -> Expression {
match &elem.borrow().base_type {
Type::Component(base_comp) => match &base_comp.root_element.borrow().layout_info_prop {
Some((hor, vert)) => Expression::PropertyReference(match orientation {
Orientation::Horizontal => hor.clone(),
Orientation::Vertical => vert.clone(),
}),
None => Expression::FunctionCall {
let mut elem_it = elem.clone();
loop {
return match &elem_it.clone().borrow().base_type {
Type::Component(base_comp) => {
match base_comp.root_element.borrow().layout_info_prop(orientation) {
Some(nr) => {
// We cannot take nr as is because it is relative to the elem's component. We therefore need to
// use `elem` as an element for the PropertyReference, not `root` within the base of elem
debug_assert!(Rc::ptr_eq(&nr.element(), &base_comp.root_element));
Expression::PropertyReference(NamedReference::new(elem, nr.name()))
}
None => {
elem_it = base_comp.root_element.clone();
continue;
}
}
}
Type::Builtin(base_type) if base_type.name == "Rectangle" => {
// hard-code the value for rectangle because many rectangle end up optimized away and we
// don't want to depend on the element.
Expression::Struct {
ty: layout_info_type(),
values: [("min", 0.), ("max", f32::MAX), ("preferred", 0.)]
.iter()
.map(|(s, v)| (s.to_string(), Expression::NumberLiteral(*v as _, Unit::Px)))
.chain(
[("min_percent", 0.), ("max_percent", 100.), ("stretch", 1.)]
.iter()
.map(|(s, v)| {
(s.to_string(), Expression::NumberLiteral(*v, Unit::None))
}),
)
.collect(),
}
}
_ => Expression::FunctionCall {
function: Box::new(Expression::BuiltinFunctionReference(
BuiltinFunction::ImplicitLayoutInfo(orientation),
None,
)),
arguments: vec![Expression::ElementReference(Rc::downgrade(elem))],
source_location: None,
},
},
Type::Builtin(base_type) if base_type.name == "Rectangle" => {
// hard-code the value for rectangle because many rectangle end up optimized away and we
// don't want to depend on the element.
Expression::Struct {
ty: layout_info_type(),
values: [("min", 0.), ("max", f32::MAX), ("preferred", 0.)]
.iter()
.map(|(s, v)| (s.to_string(), Expression::NumberLiteral(*v as _, Unit::Px)))
.chain(
[("min_percent", 0.), ("max_percent", 100.), ("stretch", 1.)].iter().map(
|(s, v)| (s.to_string(), Expression::NumberLiteral(*v, Unit::None)),
),
)
.collect(),
}
}
_ => Expression::FunctionCall {
function: Box::new(Expression::BuiltinFunctionReference(
BuiltinFunction::ImplicitLayoutInfo(orientation),
None,
)),
arguments: vec![Expression::ElementReference(Rc::downgrade(elem))],
source_location: None,
},
};
}
}
5 changes: 4 additions & 1 deletion tests/cases/layout/override_from_parent.60
Expand Up @@ -31,6 +31,8 @@ SubComp3 := HorizontalLayout {
Rectangle { }
}

SubComp4 := SubComp1 {}


TestCase := Rectangle {
width: 300phx;
Expand All @@ -40,6 +42,7 @@ TestCase := Rectangle {
sc2 := SubComp2 {}
// FIXME: the HorizontalLayout is required here because the sc3.max-width takes the existing binding instead of being re-materialized
sc3 := HorizontalLayout { SubComp3 { width: 200px; } }
property<bool> test: sc1.min-width == 200px && sc2.min-width == 200px && sc3.max-width == 200px;
sc4 := SubComp4 {}
property<bool> test: sc1.min-width == 200px && sc2.min-width == 200px && sc3.max-width == 200px && sc4.min-width == 200px;
}

0 comments on commit 06d1293

Please sign in to comment.