fix: Pixel-snap WrapPanel layout to prevent spurious line wraps at non-integer scales#22963
fix: Pixel-snap WrapPanel layout to prevent spurious line wraps at non-integer scales#22963
Conversation
There was a problem hiding this comment.
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
MeasureOverrideandArrangeOverride - Added half-DIP tolerance to line-overflow comparisons to prevent rounding noise from triggering line wraps
- Refactored variable naming from
otoorientationfor improved clarity - Updated
ArrangeLinemethod 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.
|
the linked issue is fixed by another PR in unoplatform/Uno.WindowsCommunityToolkit/pull/235 |
dbbbdf7 to
1867799
Compare
|
🤖 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 |
1867799 to
2f3e16c
Compare
2f3e16c to
a9c4e1c
Compare
There was a problem hiding this comment.
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.
|
🤖 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 |
|
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
a9c4e1c to
7c00b06
Compare
|
🤖 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 |
GitHub Issue: re: https://github.com/unoplatform/kahua-private/issues/427
PR Type:
🐞 Bugfix
What is the current behavior? 🤔
WrapPanelaccumulates child sizes as rawdoublevalues. 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 bothMeasureOverrideandArrangeOverride. 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 toLayoutHelper.LayoutRoundto clarify its purpose.PR Checklist ✅
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information ℹ️
Runtime tests added in
Given_WrapPanel.cscovering wrap behavior at integer and non-integer scales.