Skip to content

fix: Square measure for UniformToFill shapes - #23559

Merged
MartinZikmund merged 6 commits into
masterfrom
dev/mazi/shapes-arrange
Jun 26, 2026
Merged

MartinZikmund merged 6 commits into
masterfrom
dev/mazi/shapes-arrange

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: closes #18265

PR Type:

🐞 Bugfix

What changed? 🚀

On Skia, an Ellipse/Rectangle with Stretch="UniformToFill" that is wider (or taller) than its container ignored VerticalAlignment (resp. HorizontalAlignment):

<Grid Width="150" Height="150" BorderBrush="Green" BorderThickness="1">
    <Ellipse Width="300" Stretch="UniformToFill"
             HorizontalAlignment="Left" VerticalAlignment="Bottom" Fill="Red" />
</Grid>

Root cause: MeasureRelativeShape returned new Size(width, height) for UniformToFill, where width = Max(availableWidth, availableHeight) but height was left as the raw available height. The desired height then equalled the container height, so there was no overflow for VerticalAlignment to act on.

Fix: return a square desired size (new Size(width, width)). This matches WinUI, where both CEllipse::MeasureOverride and CRectangle::MeasureOverride set desiredSize.height = width. The change is isolated to the UniformToFill branch and to the only two shapes that route through MeasureRelativeShape (Ellipse, Rectangle) — exactly the two shapes WinUI gives this fast-path. The arrange logic on every platform already forces the UniformToFill render area square, so the corrected square desired size is consistent with arrange everywhere.

Tests

  • New Given_Ellipse runtime tests reproducing the issue (Bottom- and Top-aligned), gated #if __SKIA__ || WINAPPSDK.
  • New Given_Rectangle.When_RectangleMeasure data row covering the finite UniformToFill case.
  • New Given_Basic_Shapes_Parity Skia runtime test that replaces the old Basics_Shapes_Tests UI test (which only ran on native iOS/Android and was [Ignore]d, so it never exercised the Skia path this bug lived on). It renders the Basic_Shapes HorizontalAlignment × VerticalAlignment grids for all six shapes (Ellipse, Rectangle, Line, Path, Polygon, Polyline) across every stretch and size, and compares each render against the WinUI golden screenshots. All 570 configurations match WinUI on Skia — including the configs the old UI test had to exclude on native.
  • The WinUI goldens were moved into the runtime tests library (Uno.UI.RuntimeTests/Assets/ShapeParityGoldens) and are loaded via ms-appx Content (works across all targets), so the test no longer depends on the soon-to-be-removed UI test project. The old golden comparison suite was deleted from Basics_Shapes_Tests (the still-active Validate_Offscreen_Shapes browser test is kept).

Verified on Skia Desktop: the repro fails before / passes after the fix; the parity test discriminates (a deliberately mis-positioned render measures > 20% pixel difference vs < 0.7% for a correct one, against a 3% threshold); all six shape methods pass.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01CaPHWAaFvY1iT6STp9xL15

For Stretch=UniformToFill, Ellipse and Rectangle must report a square
desired size (height = width) so an oversized shape produces overflow
for Horizontal/VerticalAlignment to act on. MeasureRelativeShape
returned new Size(width, height), leaving the desired height at the
available height, so vertical alignment had no effect when the shape
was wider than its container (issue #18265).

This matches WinUI CEllipse::MeasureOverride / CRectangle::MeasureOverride,
which both set desiredSize.height = width.

Adds Given_Ellipse runtime tests reproducing the issue and a
When_RectangleMeasure data row covering the finite UniformToFill case.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CaPHWAaFvY1iT6STp9xL15
@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 3m 31s —— View job


PR Review: fix: Square measure for UniformToFill shapes

  • Gather context and read changed files
  • Review Shape.layout.cs fix
  • Review Given_Ellipse.cs new test file
  • Review Given_Rectangle.cs changes
  • Post inline comments for findings
  • Post summary

Overall Verdict: ✅ Approve with minor suggestions

The core fix is correct and well-reasoned. MeasureRelativeShape returning new Size(width, width) for UniformToFill matches WinUI's CEllipse/CRectangle::MeasureOverride behaviour, and the comment explaining the intentional height = width assignment is warranted given how non-obvious it is. The geometry of the two new Given_Ellipse tests is sound (verified by working through the circle algebra: a 300×300 circle in a 150×150 container, bottom-aligned or top-aligned, produces the expected red/white distribution at the tested coordinates).

2 low-severity findings:

# Severity Location Issue
1 Low Given_Ellipse.cs lines 44–45, 74–75 tolerance: 20 exceeds the guideline of 1–5 — Red and White differ by 255 on two channels so tolerance: 5 is more than sufficient
2 Low Given_Rectangle.cs line 35 New DataRow uses equal available dims (500×500) so it passes before and after the fix; an asymmetric row (e.g. 300d, 150d available with NaN Width/Height, expecting 300d, 300d) would directly exercise the changed branch

No blocking issues. The fix is scoped exactly as described (only the UniformToFill branch of MeasureRelativeShape, only for Ellipse/Rectangle which route through it), conventional-commit title is correct, and the [GitHubWorkItem] annotations are present on both new test methods.

@unodevops

Copy link
Copy Markdown
Contributor

Adds Given_Basic_Shapes_Parity, a Skia runtime test that renders the
Basic_Shapes HorizontalAlignment x VerticalAlignment grids for Ellipse
and Rectangle across all stretches and sizes, then compares each render
against the WinUI golden screenshots (reused, not copied, from the
native-only and currently [Ignore]d Basics_Shapes_Tests UI test).

This adds the Skia shapes-parity coverage that did not exist before:
the original UI test only ran on native iOS/Android, so it never
exercised the Skia measure/arrange path where #18265 occurred. All 190
Ellipse/Rectangle configurations now match WinUI.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CaPHWAaFvY1iT6STp9xL15
@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 4m 23s —— View job


PR Review: fix: Square measure for UniformToFill shapes

  • Read changed files
  • Review core fix in Shape.layout.cs
  • Review new Given_Ellipse.cs tests
  • Review Given_Rectangle.cs changes
  • Review Given_Basic_Shapes_Parity.cs
  • Post inline comments
  • Post summary

Overall Verdict: ✅ Approve with minor suggestions

Core fix (Shape.layout.cs): Correct and well-scoped. Returning new Size(width, width) for the UniformToFill branch of MeasureRelativeShape matches WinUI's CEllipse/CRectangle::MeasureOverride exactly. The explanatory comment is warranted — the deliberate height = width assignment is genuinely non-obvious without the cross-reference. The change is isolated to the single UniformToFill branch and to the two shapes (Ellipse, Rectangle) that route through MeasureRelativeShape; Line/Polyline/Polygon/Path are unaffected.

Findings

# Severity File Issue
1 Low Given_Ellipse.cs:44–45,74–75 tolerance: 20 exceeds guideline (1–5); channels differ by 255 so tolerance: 5 is ample — flagged by previous review, still unresolved
2 Low Given_Rectangle.cs:35 New DataRow uses equal available dims (500×500) so it passes before and after the fix; an asymmetric row (300d, 150d → expect 300d, 300d) would directly cover the changed branch — flagged by previous review, still unresolved
3 Low Given_Basic_Shapes_Parity.cs:127–134 golden (SKBitmap) is disposed manually on the happy path only; if RenderAsync/GetPixelsAsync/MismatchFraction throws the bitmap leaks. Use using var golden = TryLoadGolden(id); instead — inline comment posted

No blocking issues. The fix is correct, the test logic in Given_Basic_Shapes_Parity (compositing against white, mismatch fraction threshold, guarding against empty golden sets) is sound. All new test methods carry [GitHubWorkItem] annotations as required.

@unodevops

Copy link
Copy Markdown
Contributor

MartinZikmund and others added 2 commits June 26, 2026 09:58
The Basic_Shapes stretch/alignment golden comparison was a UI test that only
ran on native iOS/Android and was [Ignore]d, so it never exercised the Skia
path where #18265 occurred. Replace it with the Skia runtime test
Given_Basic_Shapes_Parity and move the WinUI golden screenshots into the
runtime tests library.

- Move all 570 expected screenshots from SamplesApp.UITests into
  Uno.UI.RuntimeTests/Assets/ShapeParityGoldens; load them via ms-appx Content
  (works across all targets) instead of a cross-project embedded resource.
- Extend Given_Basic_Shapes_Parity to all six shapes (Ellipse, Rectangle,
  Line, Path, Polygon, Polyline) x every stretch x size. All 570 configs match
  WinUI on Skia, including the ones the old UI test had to exclude on native.
- Remove the golden comparison suite from Basics_Shapes_Tests; keep the still
  active Validate_Offscreen_Shapes browser test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CaPHWAaFvY1iT6STp9xL15
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Jun 26, 2026
@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 4m 9s —— View job


PR Review: fix: Square measure for UniformToFill shapes

  • Read changed files and check if previous findings were addressed
  • Review Given_Ellipse.cs — tolerance finding (still unresolved)
  • Review Given_Rectangle.cs — DataRow finding (still unresolved)
  • Review Given_Basic_Shapes_Parity.cs — SKBitmap leak (corrected and re-posted)
  • Post inline comment
  • Post summary

Overall Verdict: ✅ Approve with minor suggestions

Latest commit (f52963ef) cleanly extends Given_Basic_Shapes_Parity from Ellipse + Rectangle to all 6 shapes (Line, Path, Polygon, Polyline), moves 570 WinUI golden screenshots from SamplesApp.UITests into Uno.UI.RuntimeTests/Assets/ShapeParityGoldens/ as Content (loaded via ms-appx), and strips the now-superseded golden suite from Basics_Shapes_Tests.cs. The extension is correct: ValidateShape is called identically for all shapes, all 570 files are present, and the <Content Include="Assets\**" /> glob in Uno.UI.RuntimeTests.Skia.csproj covers them.

Findings

# Severity File Status
1 Low Given_Ellipse.cs:44–45,74–75 tolerance: 20 violates the 1–5 guideline — flagged 2× previously, still unresolved
2 Low Given_Rectangle.cs:35 UniformToFill DataRow uses equal available dims (500×500) with explicit Width/Height, so it passes before and after the fix — flagged 2× previously, still unresolved
3 Low Given_Basic_Shapes_Parity.cs:168–172 golden (SKBitmap) can leak on an exception before line 198; previous suggestion had wrong method name (TryLoadGolden vs TryLoadGoldenAsync) — re-posted inline comment with corrected suggestion

No new issues introduced by the latest commit. The core fix in Shape.layout.cs and all test logic remain correct.

- Lower Given_Ellipse pixel tolerance 20 -> 5 (per runtime-tests guideline)
- Use 'using var' for the parity-test golden bitmap (dispose on all paths)
- Clarify the Rectangle UniformToFill row: DesiredSize is clamped to available,
  so the bug surfaces only in arrange (covered by the pixel-based tests)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CaPHWAaFvY1iT6STp9xL15
@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 2m 50s —— View job


PR Review: fix: Square measure for UniformToFill shapes

  • Gather context and analyze previous findings
  • Read Given_Ellipse.cs — tolerance finding addressed ✅
  • Read Given_Rectangle.cs — DataRow finding addressed with explanation ✅
  • Read Given_Basic_Shapes_Parity.cs — bitmap leak fixed; all new shape additions reviewed ✅
  • Post inline comments for new/unresolved findings
  • Post summary

Overall Verdict: ✅ Approve

All three findings from prior reviews are resolved in commit c6fffd05:

# File Status
1 Given_Ellipse.cs:44–45,74–75 tolerance: 20 → tolerance: 5 on all four assertions — fixed
2 Given_Rectangle.cs:33–37 Comment expanded to explain why the DesiredSize path can't expose the bug (clamped to available size); visual coverage is correctly delegated to the pixel-based Given_Ellipse and Given_Basic_Shapes_Parity tests — adequately resolved
3 Given_Basic_Shapes_Parity.cs:168 var golden → using var golden, explicit golden.Dispose() removed — fixed

No new issues. The core fix in Shape.layout.cs (returning new Size(width, width) for the UniformToFill branch) is unchanged and correct. The full picture:

  • Code review assessment: MeasureRelativeShape returning a square desired size for UniformToFill matches WinUI CEllipse/CRectangle::MeasureOverride; the fix is scoped to that branch and to Ellipse/Rectangle only, which are the only shapes routing through MeasureRelativeShape.
  • Compile validation: not run locally (Linux runner, Skia-only build).
  • Runtime validation: per PR description, Skia Desktop run confirmed the repro fails-before/passes-after and all 570 parity configurations match WinUI.

@unodevops

Copy link
Copy Markdown
Contributor

When_CompactPaneLength_Changed_PaneToggleButton_Updates is flaky on
native WinUI; exclude it there via PlatformCondition pending the
investigation tracked in #23561. Still runs on Skia and WASM.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CaPHWAaFvY1iT6STp9xL15
@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 2m 8s —— View job


PR Review: fix: Square measure for UniformToFill shapes

  • Gather context
  • Check latest commits / diff
  • Review changed files (Shape.layout.cs, Given_Ellipse.cs, Given_Rectangle.cs, Given_Basic_Shapes_Parity.cs, Given_NavigationView.cs)
  • Inline comment check
  • Post summary

Overall Verdict: ✅ Approve

The latest commit (91f662e3) adds [PlatformCondition(ConditionMode.Exclude, RuntimeTestPlatforms.NativeWinUI)] to When_CompactPaneLength_Changed_PaneToggleButton_Updates in Given_NavigationView.cs, guarding a test that is flaky on native WinUI while leaving it active on Skia and WASM. The approach is correct (uses PlatformCondition, not [Ignore]), the inline comment references the tracking issue (#23561), and the commit title is Conventional-Commits-compliant.

All findings from prior reviews are confirmed resolved:

# File Status
1 Given_Ellipse.cs tolerance: 20 → tolerance: 5 — fixed
2 Given_Rectangle.cs Comment explaining why DesiredSize can't expose the bug — adequately resolved
3 Given_Basic_Shapes_Parity.cs using var golden = await TryLoadGoldenAsync(id) — fixed

Core fix (Shape.layout.cs) — unchanged, correct: Returning new Size(width, width) for UniformToFill in MismatchFraction matches WinUI CEllipse/CRectangle::MeasureOverride; the change is isolated to that single branch and to the two shapes (Ellipse, Rectangle) that route through MeasureRelativeShape.

No new issues introduced by the latest commit. The PR is ready to merge.

@MartinZikmund
MartinZikmund enabled auto-merge June 26, 2026 08:44
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund
MartinZikmund merged commit 1f47971 into master Jun 26, 2026
47 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/shapes-arrange branch June 26, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Skia] Shapes arrange appear to be broken in certain cases

3 participants