-
Notifications
You must be signed in to change notification settings - Fork 188
[Win32] Make Control bounds point/pixel conversion cope with rounding #2782
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: master
Are you sure you want to change the base?
[Win32] Make Control bounds point/pixel conversion cope with rounding #2782
Conversation
The invertibility of point/pixel conversions is limited as point values are int-based and with lower resolution than pixel values. In consequence, values need to be rounded when converted between the two, which inevitably leads to rounded values that do not fit for every use case. This adds test cases that demonstrate such use cases, including simple parent/child scenarios, in which the child is supposed to fill the parent, and including layouting scenarios incorporating the client area of a composite, and how the current implementation is not capable of producing proper results for them. This change also adapts the methods for setting bounds/size of controls to deal with the limited invertibility: 1. They transform the passed bounds into a "global" coordinate system (the one of the containing shell) such that all values are rounded in the same way. Otherwise, every control uses a coordinate system relative to its parent, leading to the same global point coordinates being transformed to different pixel coordinates, such that parent and child may not fit to each other even though their point coordinates perfectly match. 2. They shrink the calculated pixel values by at most the maximum error that can be made when transforming from point to pixel values, such that rounding errors due to layouts that calculated control bounds based on a composites client area are evened out. Without that, layouted controls may be up to one point too large to fit into the composite.
55f83e3 to
3924200
Compare
Test Results 115 files - 3 115 suites - 3 11m 11s ⏱️ - 7m 0s Results for commit 3924200. ± Comparison against base commit 0b21ff2. This pull request removes 37 and adds 3 tests. Note that renamed tests count towards both.This pull request skips 1 and un-skips 1 tests. |
|
Thank you, @amartya4256! I am still analyzing the issue you reported. All values (bounds in points and pixels of involved controls) look fine, but still something is not fitting. Since this PR combines two improvements anyway, I have extracted the one part that does not seem to break anything (and the part that is more important anyway) to a separate PR, so that we can at least move on with that: |

The invertibility of point/pixel conversions is limited as point values are int-based and with lower resolution than pixel values. In consequence, values need to be rounded when converted between the two, which inevitably leads to rounded values that do not fit for every use case. This adds test cases that demonstrate such use cases, including simple parent/child scenarios, in which the child is supposed to fill the parent, and including layouting scenarios incorporating the client area of a composite, and how the current implementation is not capable of producing proper results for them.
This change also adapts the methods for setting bounds/size of controls to deal with the limited invertibility:
Examples
The different issues are demonstrated with the following snippet (conforms to the test cases):
Before at 125%:

After at 125%:

You can easily see the behavior in layouted controls (particularly using grid layouts), such as controls based on Forms UI:
Before at 125%:

After at 125%:
