Cache source measurements and propagate native viewport inputs
Verify Tessera GUI / verify (push) Failing after 7m29s

This commit is contained in:
2026-10-21 16:33:35 +08:00
parent 1b5fe1069f
commit 3ea4bac48c
12 changed files with 744 additions and 37 deletions
+49 -5
View File
@@ -38,6 +38,7 @@ pub struct LayoutRuntime {
pub version: u64,
pub measured: usize,
pub arranged: usize,
pub viewport: Option<Size>,
}
struct Item<'a> {
@@ -45,6 +46,7 @@ struct Item<'a> {
parent: Option<usize>,
children: Vec<usize>,
id: u64,
constraints: [f32; 4],
}
fn bounded(value: f32) -> Result<f32> {
@@ -54,6 +56,37 @@ fn bounded(value: f32) -> Result<f32> {
Ok(value)
}
pub fn root_constraints(viewport: Option<Size>) -> [f32; 4] {
let size = viewport.unwrap_or(Size {
width: MAX_DIMENSION as f32,
height: MAX_DIMENSION as f32,
});
[0.0, 0.0, size.width, size.height]
}
pub fn child_constraints(node: &UiNode, parent: [f32; 4]) -> [f32; 4] {
match container(node) {
Some((true, padding, _)) => [
0.0,
0.0,
MAX_DIMENSION as f32,
(parent[3] - padding * 2.0).max(0.0),
],
Some((false, padding, _)) => [
0.0,
0.0,
(parent[2] - padding * 2.0).max(0.0),
MAX_DIMENSION as f32,
],
None => parent,
}
}
pub fn constrained(size: Size, constraints: [f32; 4]) -> Size {
Size {
width: size.width.clamp(constraints[0], constraints[2]),
height: size.height.clamp(constraints[1], constraints[3]),
}
}
fn container(node: &UiNode) -> Option<(bool, f32, f32)> {
match &node.kind {
UiKind::Row { padding, gap, .. } => Some((true, *padding, *gap)),
@@ -227,9 +260,9 @@ impl LayoutRuntime {
self.measured = 0;
self.arranged = 0;
let mut items = Vec::<Item<'_>>::new();
let mut work = vec![(root, None::<usize>, 0)];
let mut work = vec![(root, None::<usize>, 0, root_constraints(self.viewport))];
let mut used = HashSet::new();
while let Some((node, parent, slot)) = work.pop() {
while let Some((node, parent, slot, constraints)) = work.pop() {
if items.len() >= MAX_LAYOUT_VISITS {
bail!("expanded UI layout exceeds 10000 nodes");
}
@@ -263,16 +296,27 @@ impl LayoutRuntime {
parent,
children: vec![],
id,
constraints,
});
for (child, slot) in node.children().iter().zip(&node.slots).rev() {
work.push((child.as_ref(), Some(index), *slot));
work.push((
child.as_ref(),
Some(index),
*slot,
child_constraints(node, constraints),
));
}
}
let mut sizes = vec![Size::default(); items.len()];
if !structural {
for (index, item) in items.iter().enumerate().rev() {
sizes[index] = self
.measure_node(item.node, item.children.iter().map(|i| sizes[*i]).collect())?;
sizes[index] = constrained(
self.measure_node(
item.node,
item.children.iter().map(|i| sizes[*i]).collect(),
)?,
item.constraints,
);
}
}
let mut points = vec![(0.0_f32, 0.0_f32); items.len()];