Skip to content

fix: Pixel-snap WrapPanel layout to prevent spurious line wraps at non-integer scales#22963

Open
Xiaoy312 wants to merge 1 commit intomasterfrom
dev/xygu/20260403/wrappanel-layout
Open

fix: Pixel-snap WrapPanel layout to prevent spurious line wraps at non-integer scales#22963
Xiaoy312 wants to merge 1 commit intomasterfrom
dev/xygu/20260403/wrappanel-layout

Conversation

@Xiaoy312
Copy link
Copy Markdown
Contributor

@Xiaoy312 Xiaoy312 commented Apr 3, 2026

GitHub Issue: re: https://github.com/unoplatform/kahua-private/issues/427

PR Type:

🐞 Bugfix

What is the current behavior? 🤔

WrapPanel accumulates child sizes as raw double values. At non-integer display scales (e.g. 1.25×, 1.5×), floating-point rounding errors cause the accumulated line width to slightly exceed the available width, triggering spurious line breaks and producing an incorrect layout.

What is the new behavior? 🚀

Child sizes and accumulated direct-axis offsets are snapped to physical pixel boundaries (via LayoutHelper.LayoutRound) in both MeasureOverride and ArrangeOverride. A half-DIP tolerance is added to line-overflow comparisons so that pixel-boundary rounding noise does not falsely trigger a new line. An XML doc comment was also added to LayoutHelper.LayoutRound to clarify its purpose.

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Other information ℹ️

Runtime tests added in Given_WrapPanel.cs covering wrap behavior at integer and non-integer scales.

Copilot AI review requested due to automatic review settings April 3, 2026 21:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug in WrapPanel where floating-point rounding errors at non-integer display scales (e.g., 1.25×, 1.5×) cause spurious line wraps. The fix applies pixel-boundary snapping to child sizes and accumulated offsets using the new LayoutHelper.LayoutRound method, and adds a half-DIP tolerance to line-overflow comparisons.

Changes:

  • Added LayoutHelper.LayoutRound() method with XML documentation to snap values to physical pixel boundaries
  • Applied pixel snapping to child sizes and accumulated offsets in both MeasureOverride and ArrangeOverride
  • Added half-DIP tolerance to line-overflow comparisons to prevent rounding noise from triggering line wraps
  • Refactored variable naming from o to orientation for improved clarity
  • Updated ArrangeLine method signature to accept and use the scale parameter
  • Added runtime test for WrapPanel wrapping behavior at non-integer scales (1.25×)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Uno.UI/UI/LayoutHelper.cs Added LayoutRound helper method with XML documentation for pixel-boundary snapping
src/Uno.UI/UI/Xaml/Controls/WrapPanel/WrapPanel.Layout.cs Applied pixel snapping to layout calculations in MeasureOverride and ArrangeOverride; updated variable names and ArrangeLine signature
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_WrapPanel.cs Added regression test for wrap behavior at non-integer scales

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Xiaoy312
Copy link
Copy Markdown
Contributor Author

Xiaoy312 commented Apr 3, 2026

the linked issue is fixed by another PR in unoplatform/Uno.WindowsCommunityToolkit/pull/235
this PR addresses a similar problem found within WrapPanel

@Xiaoy312 Xiaoy312 force-pushed the dev/xygu/20260403/wrappanel-layout branch from dbbbdf7 to 1867799 Compare April 3, 2026 21:37
@unodevops
Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22963/wasm-skia-net9/index.html

@Xiaoy312 Xiaoy312 force-pushed the dev/xygu/20260403/wrappanel-layout branch from 1867799 to 2f3e16c Compare April 4, 2026 02:18
Copilot AI review requested due to automatic review settings April 4, 2026 02:18
@Xiaoy312 Xiaoy312 force-pushed the dev/xygu/20260403/wrappanel-layout branch from 2f3e16c to a9c4e1c Compare April 4, 2026 02:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops
Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22963/wasm-skia-net9/index.html

@unodevops
Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 205549 has failed on Uno.UI - CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Xiaoy312 Xiaoy312 force-pushed the dev/xygu/20260403/wrappanel-layout branch from a9c4e1c to 7c00b06 Compare April 10, 2026 17:38
@unodevops
Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22963/wasm-skia-net9/index.html

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.

5 participants