feat: allocate weighted flex space and remeasure affected occurrences
Verify Tessera GUI / verify (push) Failing after 7m59s
Verify Tessera GUI / verify (push) Failing after 7m59s
This commit is contained in:
@@ -260,6 +260,54 @@ pub fn paint_native(node: &UiNode, x: f32, y: f32, size: Size) -> Option<RenderC
|
||||
}
|
||||
}
|
||||
|
||||
/// Zero-basis weighted allocation within the space actually assigned to a
|
||||
/// native container. Fixed children keep their measured sizes.
|
||||
pub fn flex_sizes(node: &UiNode, bounds: Size, children: &[Size]) -> Vec<Size> {
|
||||
let Some((row, padding, gap)) = container(node) else {
|
||||
return children.to_vec();
|
||||
};
|
||||
let flexible: Vec<_> = node
|
||||
.children()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, child)| child.flex > 0.0)
|
||||
.collect();
|
||||
if flexible.is_empty() {
|
||||
return children.to_vec();
|
||||
}
|
||||
let fixed = children
|
||||
.iter()
|
||||
.zip(node.children())
|
||||
.filter(|(_, child)| child.flex == 0.0)
|
||||
.map(|(size, _)| if row { size.width } else { size.height })
|
||||
.sum::<f32>();
|
||||
let available = ((if row { bounds.width } else { bounds.height })
|
||||
- padding * 2.0
|
||||
- gap * children.len().saturating_sub(1) as f32
|
||||
- fixed)
|
||||
.max(0.0);
|
||||
let total = flexible
|
||||
.iter()
|
||||
.map(|(_, child)| child.flex as f64)
|
||||
.sum::<f64>();
|
||||
let mut output = children.to_vec();
|
||||
let mut remaining = available;
|
||||
for (position, (index, child)) in flexible.iter().enumerate() {
|
||||
let share = if position + 1 == flexible.len() {
|
||||
remaining
|
||||
} else {
|
||||
((available as f64 * child.flex as f64 / total) as f32).min(remaining)
|
||||
};
|
||||
if row {
|
||||
output[*index].width = share;
|
||||
} else {
|
||||
output[*index].height = share;
|
||||
}
|
||||
remaining = (remaining - share).max(0.0);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
pub fn arrange_native(
|
||||
node: &UiNode,
|
||||
x: f32,
|
||||
@@ -460,6 +508,11 @@ impl LayoutRuntime {
|
||||
continue;
|
||||
}
|
||||
let child_sizes: Vec<_> = item.children.iter().map(|child| sizes[*child]).collect();
|
||||
let child_sizes = flex_sizes(item.node, size, &child_sizes);
|
||||
for (child, allocated) in item.children.iter().zip(&child_sizes) {
|
||||
sizes[*child] = *allocated;
|
||||
}
|
||||
|
||||
for (child, point) in
|
||||
item.children
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user