-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix Android arrange coordinate conversion #27179
base: main
Are you sure you want to change the base?
Conversation
@albyrock87 Just a random person here, but that looks like a solid explanation to add also in the code so it's easily discoverable also later to whoever reads the code. |
Hey there @albyrock87! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
I've added the comments in the code. That said, I'm afraid this PR will generate UITests failures everywhere and it'll take forever to capture all the screenshots. |
We have another option to not break all the UI tests: keep the |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
In theory it should generated the needed screenshots and we can just replace, or we can ask for help to finish that tedious work of updating the screenshots. |
once we see the screenshots that'll give us an idea of the magnitude of change. There's definitely a lot :-) |
I think this change makes sense... I'm a little curious about the initial conversion from px to dp and if we should be rounding that Like, if a DP value is 294.0000000000001 it seems like we should just convert that to 294 when doing the PX to DP conversion I'm also wondering if we should midpoint round the width and height also. It seems like that's how Android suggests always doing the rounding https://developer.android.com/training/multiscreen/screendensities#dips-pels |
I'm afraid that value comes from the centering algorithm (in this specific example) and not from PX to DP conversion. Obviously the centering algorithm uses DP coming from a measure pass which is in PX, but that's a plain I also wonder why we're going through |
var top = Context.ToPixels(frame.Top); | ||
var bottom = Context.ToPixels(frame.Bottom); | ||
var right = Context.ToPixels(frame.Right); | ||
var (left, top, right, bottom) = context.ToPixels(frame); |
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.
Slightly impacts tests with Labels and custom FontFamily (around 1-2% of changes detected when checking the image).
Failing tests:
- FontFamily
- FontFamilyLoadsDynamically
- VerifyTextDecorationAppliedProperly
- Bugzilla53834Test
- ChildFlexLayoutContentShouldAppear
- SystemFontsShouldRenderCorrectly
- LabelHyperlinkUnderlineColor
Could you review and update the failing ones? Let me know if can help with something.
{ | ||
EnsureMetrics(self); | ||
|
||
return (float)Math.Round(dp * s_displayDensity, MidpointRounding.AwayFromZero); |
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.
Apart from the UITest, could be nice to include some device tests checking conversions.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Description of Change
Android emulator (for instance) has 2.625 display density multiplier.
Let's say you're arranging a label to this frame:
If we convert this to pixels (
Ceiling
is how MAUI rounds it) we getNow here's the deal: the output rectangle must have width = 492px.
Problem is: when arranging, MAUI is converting
left, right, top, bottom
coordinates separately, whereright = X + Width
(same forbottom
).So basically we get
which is
Now if we do
786px - 295px
we get491px
which is less than492px
expected platform width.This is the reason the
Label
is being cut-off.The reason MAUI is
Ceiling
when converting to pixel is exactly to avoid cutting content, but that's a valid reasoning only when talking aboutwidth
orheight
.The coordinate system should instead follow the
Round
ing principle to accomodate the content to the nearest pixel: in the example above, it makes no sense to convert294.00000000000006
to295
.This PR applies this reasoning to the arrange system.
Issues Fixed
Fixes #17884