Repository navigation
fix(ZoomContentControl): re-fit/center when AdditionalMargin changes - #1611
Conversation
- `AdditionalMargin` insets the usable viewport and participates in `FitToCanvas`/`CenterContent`, but `OnAdditionalMarginChanged` only refreshed the scrollbars, so content stayed fitted/centered against the previous margin until an unrelated size/zoom change re-fit it. - Mirror `OnViewportSizeChanged`: call `UpdateScrollDetails()` so the auto fit/center pass re-runs (gated on `AutoFitToCanvas`/`AutoCenterContent`). - Add runtime tests (red/fix/green): re-fit on margin increase; no forced re-fit when `AutoFitToCanvas` is disabled.
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://polite-field-01aa64f0f-1611.eastus2.azurestaticapps.net |
There was a problem hiding this comment.
Pull request overview
This PR fixes ZoomContentControl layout consistency by treating AdditionalMargin changes as a usable-viewport change: updating the margin now re-runs the same auto fit/center pipeline used for viewport size changes, preventing “it fixes itself on next resize” behavior.
Changes:
- Call
UpdateScrollDetails()fromOnAdditionalMarginChanged()soAutoFitToCanvas/AutoCenterContentare re-applied when the margin changes. - Add runtime tests covering re-fit behavior when
AdditionalMarginchanges (with AutoFit enabled and disabled). - Update the control documentation (and add a small spec) to reflect the behavioral contract.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Uno.Toolkit.UI/Controls/ZoomContentControl/ZoomContentControl.cs | Re-run auto fit/center + scrollbar update when AdditionalMargin changes. |
| src/Uno.Toolkit.RuntimeTests/Tests/ZoomContentControlAdditionalMarginTests.cs | Adds regression/guard runtime tests for AdditionalMargin triggering (or not triggering) refit. |
| specs/zoomcontentcontrol-refit-on-additionalmargin/spec.md | Documents expected behavior and test requirements for the fix. |
| doc/controls/ZoomContentControl.md | Clarifies AdditionalMargin semantics and that it triggers auto fit/center when enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
Fixes spellcheck failures on the ZoomContentControl AdditionalMargin re-fit spec (lines 14 and 58).
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://polite-field-01aa64f0f-1611.eastus2.azurestaticapps.net |
|
Congrats on your first pull-request! We ❤ the people who are involved in this project, and we’d love to pay it forward by sending you some swag. If you have any feedback (or ideas how to improve Uno as a open-source project) please open a feedback issue. |
|
/unobot prepare-release --commit-message-pattern "ci: Set version to '{0}'" |

GitHub Issue (If applicable): #
PR Type
What is the current behavior?
ZoomContentControl.AdditionalMargininsets the usable viewport — it is subtracted from the viewport inFitToCanvasand participates in the centering math (ClippedViewportSize,PaddedScaledContentSize). Every other input that affects the fitted/centered layout (viewport size, content size, content reload) re-runs the auto fit/center pass viaUpdateScrollDetails(), but a change toAdditionalMargindoes not —OnAdditionalMarginChangedonly refreshed the scrollbars:As a result, with
AutoFitToCanvas="True"(and/orAutoCenterContent="True"), setting/changingAdditionalMarginafter layout leaves the content fitted/centered against the previous margin. When the new margin is larger, the content can extend into the region the margin was meant to reserve; a later viewport/content/zoom change corrects it (the tell-tale "fixes itself on the next resize").What is the new behavior?
A change to
AdditionalMarginnow re-runs the auto fit/center pass, consistent with a viewport-size change (a margin change is effectively a change to the usable viewport).OnAdditionalMarginChangedmirrorsOnViewportSizeChanged:UpdateScrollDetails()already gates the fit/center onAutoFitToCanvas/AutoCenterContent, so the opt-in contract is preserved (no re-fit is forced when those arefalse), no new state is introduced, and the single existing "re-apply layout" path is reused. Scrollbars still update andViewportSizeChangedis still raised.Runtime tests (
ZoomContentControlAdditionalMarginTests, red/fix/green):When_AdditionalMarginIncreases_AndAutoFit_ThenRefitsToSmallerZoom— repro/regression guard: fit a small content in a fixed viewport, then set a largeAdditionalMargin; the fittedZoomLevelmust decrease. Verified red (fails on the previous code — margin change did not re-fit) → green (passes with the fix), run headless via the Material sample underxvfb.When_AdditionalMarginChanges_AndAutoFitDisabled_ThenZoomUnchanged— guard: withAutoFitToCanvas="False", a margin change does not alterZoomLevel.Design spec:
specs/zoomcontentcontrol-refit-on-additionalmargin/spec.md.PR Checklist
Please check if your PR fulfills the following requirements:
doc/controls/ZoomContentControl.md(AdditionalMarginrow)Other information
TreatWarningsAsErrors); Debug build clean.AdditionalMargin,AutoFitToCanvas,AutoCenterContentare unchanged; only when the fit/center re-runs.