Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round up measurements of fixed-size stack child elements #514

Closed
wants to merge 1 commit into from

Conversation

g-mark
Copy link
Contributor

@g-mark g-mark commented Oct 1, 2024

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 g-mark requested a review from a team as a code owner October 1, 2024 14:54
@g-mark g-mark force-pushed the sgrosmark/fix/stack-measurement branch 4 times, most recently from 0943aa9 to cff2cfb Compare October 3, 2024 13:31
@g-mark g-mark force-pushed the sgrosmark/fix/stack-measurement branch from cff2cfb to b368bb7 Compare October 3, 2024 13:40
@g-mark g-mark marked this pull request as draft October 18, 2024 10:53
@g-mark g-mark closed this Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant