Skip to content

Commit 081eb9b

Browse files
akoch-yattaHeikoKlare
authored andcommitted
[win32] Unify scaling inside Control::setBounds
This commit unifies scale up results in Control::setBounds. With zoom values not dividable by 100 different result depending on using setBounds(Rectangle) or setBounds(int, int, int, int) were possible. Scaling the bounds always as rectangle solves this limitation.
1 parent 23684ac commit 081eb9b

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenario() {
5555
fontComparison.originalFontHeight, fontComparison.currentFontHeight);
5656
}
5757

58+
@Test
59+
public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {
60+
DPIUtil.setMonitorSpecificScaling(true);
61+
Display display = Display.getDefault();
62+
Shell shell = new Shell(display);
63+
DPITestUtil.changeDPIZoom(shell, 175);
64+
65+
Button button = new Button(shell, SWT.PUSH);
66+
button.setText("Widget Test");
67+
button.setBounds(new Rectangle(0, 47, 200, 47));
68+
shell.open();
69+
assertEquals("Control::setBounds(Rectangle) doesn't scale up correctly",
70+
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
71+
72+
button.setBounds(0, 47, 200, 47);
73+
assertEquals("Control::setBounds(int, int, int, int) doesn't scale up correctly",
74+
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
75+
}
76+
5877
record FontComparison(int originalFontHeight, int currentFontHeight) {
5978
}
6079

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,13 +3168,7 @@ void setBackgroundPixel (int pixel) {
31683168
* </ul>
31693169
*/
31703170
public void setBounds(int x, int y, int width, int height) {
3171-
checkWidget ();
3172-
int zoom = getZoom();
3173-
x = DPIUtil.scaleUp(x, zoom);
3174-
y = DPIUtil.scaleUp(y, zoom);
3175-
width = DPIUtil.scaleUp(width, zoom);
3176-
height = DPIUtil.scaleUp(height, zoom);
3177-
setBoundsInPixels(x, y, width, height);
3171+
setBounds(new Rectangle(x, y, width, height));
31783172
}
31793173

31803174
void setBoundsInPixels (int x, int y, int width, int height) {

0 commit comments

Comments
 (0)