fix: refresh nested flex measurements after cross-axis constraint changes
Verify Tessera GUI / verify (push) Failing after 9m2s

This commit is contained in:
2026-10-23 00:50:15 +08:00
parent 1fda07ebc5
commit 33f94da927
6 changed files with 92 additions and 4 deletions
+40 -4
View File
@@ -78,6 +78,7 @@ struct Plan {
// Source-arranged dimensions remain exact for this solve, not business state.
allocations: Vec<[Option<f32>; 2]>,
custom_arrange: Vec<bool>,
native_arrange: Vec<bool>,
custom_measure: Vec<bool>,
measured_limits: Vec<[Option<f32>; 2]>,
previous: Option<Vec<u32>>,
@@ -198,6 +199,7 @@ impl NativeCallable for Step {
};
if matches!(self.phase, Phase::Arrange) {
plan.runtime.arranged += 1;
plan.native_arrange[self.index] = intrinsic;
plan.custom_arrange[self.index] =
!intrinsic || node.children().iter().any(|child| child.has_flex());
}
@@ -448,6 +450,14 @@ impl NativeCallable for Collect {
}
let child = children[position];
if plan.custom_arrange[self.index] {
if plan.native_arrange[self.index]
&& let Some(main) = layout::main_axis(&plan.nodes[self.index])
{
// Keep an allocation explicit even if this pass's
// natural size happens to match it. It must survive
// the next parent-constraint propagation pass.
plan.allocations[child][main] = Some(bounds[main + 2]);
}
if bounds[2] != plan.sizes[child].width {
plan.allocations[child][0] = Some(bounds[2]);
}
@@ -479,7 +489,8 @@ impl NativeCallable for Settle {
.map_err(|_| invalid("layout plan poisoned"))?;
plan.runtime.settle_passes += 1;
let mut next = plan.constraints.clone();
for (index, children) in plan.children.iter().enumerate() {
for index in 0..plan.nodes.len() {
let children = plan.children[index].clone();
let [_, _, width, height] =
plan.bounds[index].ok_or(invalid("unarranged occurrence"))?;
let mut available = next[index];
@@ -502,15 +513,33 @@ impl NativeCallable for Settle {
);
for child in children {
let mut constraints = base;
if let Some(width) = plan.allocations[*child][0] {
if let Some(width) = plan.allocations[child][0] {
constraints[0] = width;
constraints[2] = width;
}
if let Some(height) = plan.allocations[*child][1] {
if let Some(height) = plan.allocations[child][1] {
constraints[1] = height;
constraints[3] = height;
}
next[*child] = constraints;
if let Some(main) = layout::main_axis(&plan.nodes[index]) {
let cross = 1 - main;
if constraints[cross] != plan.constraints[child][cross]
|| constraints[cross + 2] != plan.constraints[child][cross + 2]
{
// Wrapping or other cross-dependent measurement
// invalidates this occurrence's natural main size.
plan.preferred[child] = None;
if plan.native_arrange[index] {
// Derived flex sizes must not constrain their
// own replacement measurement. Source arrange
// allocations remain authoritative.
plan.allocations[child][main] = None;
constraints[main] = base[main];
constraints[main + 2] = base[main + 2];
}
}
}
next[child] = constraints;
}
}
let mut state = Vec::with_capacity(plan.nodes.len() * 14);
@@ -531,6 +560,12 @@ impl NativeCallable for Settle {
state.push(u32::from(dimension.is_some()));
state.push(dimension.map_or(0, bits));
}
state.push(u32::from(plan.preferred[index].is_some()));
if let Some(size) = plan.preferred[index] {
state.extend([bits(size.width), bits(size.height)]);
} else {
state.extend([0, 0]);
}
}
if plan.previous.as_ref() == Some(&state) && plan.constraints == next {
false
@@ -745,6 +780,7 @@ pub fn render(
constraints,
allocations: vec![[None, None]; count],
custom_arrange: vec![false; count],
native_arrange: vec![false; count],
custom_measure: vec![false; count],
measured_limits: vec![[None, None]; count],
previous: None,