[Win32] Make Control bounds point/pixel conversion cope with rounding#2782
[Win32] Make Control bounds point/pixel conversion cope with rounding#2782HeikoKlare wants to merge 2 commits intoeclipse-platform:masterfrom
Conversation
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: 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. # Conflicts: # bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java # bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
3924200 to
3c3a6fb
Compare
Test Results (win32) 26 files - 8 26 suites - 8 10s ⏱️ - 4m 36s For more details on these failures, see this check. Results for commit 3c3a6fb. ± Comparison against base commit 558c4e6. This pull request removes 4549 tests. |
Full set of changes, but slow with getBounds() via global coordinates
|
Closing this as it did not prove any benefits compared to the already applied improvements for handling rounding issues in control bounds. |

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%:
