-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fixed Maui.Graphics GetStringSize Inverts Width and Height #29574
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 PR fixes the incorrect sizing of text in Maui.Graphics by explicitly setting CanvasWordWrapping to NoWrap before measuring the text.
- The Windows platform implementation now reinstates NoWrap for GetStringSize.
- New test cases in both TestCases.Shared.Tests and TestCases.HostApp verify that text is rendered as a single line.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Graphics/src/Graphics/Platforms/Windows/PlatformStringSizeService.cs | Fixes GetStringSize by setting WordWrapping to NoWrap |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29562.cs | Adds automated test for verifying single-line text rendering |
src/Controls/tests/TestCases.HostApp/Issues/Issue29562.cs | Provides UI test integration to validate the fix |
/azp run MAUI-UITests-public |
public void GraphicsViewShouldNotWrapText() | ||
{ | ||
App.WaitForElement("Label"); | ||
VerifyScreenshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending snapshots. Running a build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz Added the Snapshots.
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
The values returned by canvas.GetStringSize has incorrect width and height measurements.
Root Cause
In recent changes, removed CanvasWordWrapping = NoWrap caused incorrect width and height calculations due to unintended word wrapping.
Description of Change
The fix explicitly reinstates the CanvasWordWrapping setting to NoWrap before measuring the text. This ensures that GetStringSize returns correct dimensions for single-line content, resulting in accurate rectangle sizing and proper alignment.
Validated the behaviour in the following platforms
Break PR: 29048
Issues Fixed:
Fixes #29562
Screenshots