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

Do not stretch the background #2922

Merged
merged 3 commits into from
Jul 5, 2024
Merged

Do not stretch the background #2922

merged 3 commits into from
Jul 5, 2024

Conversation

mattleibow
Copy link
Contributor

@mattleibow mattleibow commented Jul 4, 2024

Description of Change

When a view is resized, the canvas is not yet resized and updated to match. Before this PR, the canvas would be stretched to fill the view. This PR make sure to not stretch the canvas but instead keep it fixed.

The reason for the scaling in the first place is that WriteableBitmap does not have a DPI parameter. As a result, we have to create a larger bitmap than the view such that when it is scaled down to match the view size, the resolution matches that of the rest of the app. Previously, the larger canvas was just squashed to fit, but this was non-uniform. This PR always scales the canvas to the correct size preserving the aspect ratio.

Bugs Fixed

  • None.

API Changes

None.

Behavioral Changes

None.

Required skia PR

None.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Merged related skia PRs
  • Changes adhere to coding standard
  • Updated documentation

When resizing a view, the background will be stretched making the image distorted and not a great experience.

This PR make sure to never scale the background brush and rather keep it top-left aligned.
Comment on lines +104 to +105
var newDpi = root?.RasterizationScale ?? 1.0;
if (newDpi != Dpi)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check here prevents hundreds of invalidations. The XamlRootChanged event will fire when any of the properties of the XAML root changes. This does not seem to fire just when the current view gets a new XAML root as the name implies.

@mattleibow mattleibow added the backport/release/2.x Backport this PR to release/2.x label Jul 5, 2024
@mattleibow mattleibow merged commit 3ace63b into main Jul 5, 2024
2 of 3 checks passed
@mattleibow mattleibow deleted the dev/winui-scaling branch July 5, 2024 08:18
github-actions bot pushed a commit that referenced this pull request Jul 5, 2024
* Do not stretch the background

When resizing a view, the background will be stretched making the image distorted and not a great experience.

This PR make sure to never scale the background brush and rather keep it top-left aligned.

* Update SKXamlCanvas.cs

* Scale the brush instead of stretching it

(cherry picked from commit 3ace63b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/release/2.x Backport this PR to release/2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant