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
+3
View File
@@ -494,3 +494,6 @@ Block.flex is a nonnegative managed weight, default 0. In native containers, fix
Flex main-axis policy: flexBasis is "auto" by default (zero basis when flex > 0, otherwise the first measured size of this occurrence in the current solve); a number supplies an explicit basis. flexMin defaults to 0, flexMax to 1000000, and flexShrink to 0. All numbers are finite/nonnegative and at most 1000000; flexMin must not exceed flexMax. The parent clamps bases to min/max, distributes positive space by flex, and redistributes space left after a maximum is reached. Deficits shrink by flexShrink times the original basis, freezing at minima. A fixed child can opt into shrink without growth. Unresolvable minimum overflow is preserved, and remaining positive space follows mainAlign. The policy applies to width in a Row and height in Column-like containers; these are not independent width/height bounds. Source arrange overrides remain authoritative. Preferred sizes are derived per occurrence and reset for each new solve, never shared through Block state. See examples/flex-constraints.endor. Layout continuation remains unfinished.
When an occurrence's cross-axis constraint changes during settling, its preferred main-axis size is invalidated and remeasured. Any obsolete native flex allocation on that axis is removed for the replacement measurement, so narrowing a nested Column can increase wrapped text height. Source arrange allocations remain explicit. Preferred-size presence and values participate in convergence/cycle detection.
+3
View File
@@ -146,3 +146,6 @@ Trees with positive flex weights use the settling driver even when all layout me
Flex main-axis policy: flexBasis is "auto" by default (zero basis when flex > 0, otherwise the first measured size of this occurrence in the current solve); a number supplies an explicit basis. flexMin defaults to 0, flexMax to 1000000, and flexShrink to 0. All numbers are finite/nonnegative and at most 1000000; flexMin must not exceed flexMax. The parent clamps bases to min/max, distributes positive space by flex, and redistributes space left after a maximum is reached. Deficits shrink by flexShrink times the original basis, freezing at minima. A fixed child can opt into shrink without growth. Unresolvable minimum overflow is preserved, and remaining positive space follows mainAlign. The policy applies to width in a Row and height in Column-like containers; these are not independent width/height bounds. Source arrange overrides remain authoritative. Preferred sizes are derived per occurrence and reset for each new solve, never shared through Block state. See examples/flex-constraints.endor. Layout continuation remains unfinished.
When an occurrence's cross-axis constraint changes during settling, its preferred main-axis size is invalidated and remeasured. Any obsolete native flex allocation on that axis is removed for the replacement measurement, so narrowing a nested Column can increase wrapped text height. Source arrange allocations remain explicit. Preferred-size presence and values participate in convergence/cycle detection.
+3
View File
@@ -1124,6 +1124,9 @@ Block.flex is a nonnegative weight (default 0). Native containers reserve fixed
Flex main-axis policy: flexBasis is "auto" by default (zero basis when flex > 0, otherwise the first measured size of this occurrence in the current solve); a number supplies an explicit basis. flexMin defaults to 0, flexMax to 1000000, and flexShrink to 0. All numbers are finite/nonnegative and at most 1000000; flexMin must not exceed flexMax. The parent clamps bases to min/max, distributes positive space by flex, and redistributes space left after a maximum is reached. Deficits shrink by flexShrink times the original basis, freezing at minima. A fixed child can opt into shrink without growth. Unresolvable minimum overflow is preserved, and remaining positive space follows mainAlign. The policy applies to width in a Row and height in Column-like containers; these are not independent width/height bounds. Source arrange overrides remain authoritative. Preferred sizes are derived per occurrence and reset for each new solve, never shared through Block state. See examples/flex-constraints.endor. Layout continuation remains unfinished.
When an occurrence's cross-axis constraint changes during settling, its preferred main-axis size is invalidated and remeasured. Any obsolete native flex allocation on that axis is removed for the replacement measurement, so narrowing a nested Column can increase wrapped text height. Source arrange allocations remain explicit. Preferred-size presence and values participate in convergence/cycle detection.
## UI host object
Positional arguments only:
+39
View File
@@ -3889,6 +3889,45 @@ page.render(block)
);
}
#[test]
fn nested_flex_refreshes_natural_height_when_cross_width_changes() {
let (mut session, initial) = ReplSession::load(
r#"
class Narrow: Row {
function measure(self: Narrow, mount: Mount, constraints: Constraints): MeasureResult { return MeasureResult(240, 400) }
}
paragraph = TextBlock("Changing the parent's width must refresh the natural height of this wrapping paragraph. The first wide measurement must not freeze a single line of text. Changing the parent's width must refresh the natural height of this wrapping paragraph.")
paragraph.flexShrink = 1
column = Column(0, 0, paragraph)
column.flex = 1
page = Page()
page.render(Narrow(10, 0, column))
"#,
"app.main",
268,
1,
)
.unwrap();
initial.validate().unwrap();
let height: f32 = session
.execute("paragraph.mounts().at(0).bounds().height", "app.main")
.unwrap()
.value
.parse()
.unwrap();
assert!(height > 20.0);
session
.execute("paragraph.setText(\"short\")", "app.main")
.unwrap();
assert_eq!(
session
.execute("paragraph.mounts().at(0).bounds().height", "app.main")
.unwrap()
.value,
"20"
);
}
#[test]
fn bounded_flex_redistributes_growth_and_scaled_shrink() {
let (mut session, initial) = ReplSession::load(
+4
View File
@@ -177,6 +177,10 @@ fn container(node: &UiNode) -> Option<(bool, f32, f32)> {
}
}
pub fn main_axis(node: &UiNode) -> Option<usize> {
container(node).map(|(row, _, _)| usize::from(!row))
}
fn measure_shape(shape: &Shape) -> Result<Size> {
let size = match shape {
Shape::Text(value, size, width) => {
+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,