Blueprint icon indicating copy to clipboard operation
Blueprint copied to clipboard

Round up measurements of fixed-size stack child elements

Open g-mark opened this issue 4 months ago • 0 comments

Without rounding up the measured size of Stack's fixed-size child elements, rounding errors and/or floating representations can result in layout issues with a child that should almost exactly fit in a stack, and these children are not being snapped to pixel edges.

This can be seen it in the added unit test. Consider this row:

Row {
    TestElement(width: 80.25).stackLayoutChild(priority: .fixed)
    TestElement(width: 80.25).stackLayoutChild(priority: .fixed)
}

When laid out on an @2x device, without the fix:

  • child 1 has a width of 80.25, positioned at x = 0
  • child 2 also has a width of 80.25, positioned at x = 80.25
  • the row has a width of 161

After the fix, the row still has a width of 161, and:

  • child 1 has a width of 80.5, positioned at x = 0
  • child 2 also has a width of 80.5, positioned at x = 80.5
  • cumulative width of children == width of the row

g-mark avatar Oct 01 '24 14:10 g-mark