Skip to content

Commit 59d2913

Browse files
committed
[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 56767ec commit 59d2913

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
@@ -58,6 +58,25 @@ public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenario() {
5858
record FontComparison(int originalFontHeight, int currentFontHeight) {
5959
}
6060

61+
@Test
62+
public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {
63+
DPIUtil.setMonitorSpecificScaling(true);
64+
Display display = Display.getDefault();
65+
Shell shell = new Shell(display);
66+
DPITestUtil.changeDPIZoom(shell, 175);
67+
68+
Button button = new Button(shell, SWT.PUSH);
69+
button.setText("Widget Test");
70+
button.setBounds(new Rectangle(0, 47, 200, 47));
71+
shell.open();
72+
assertEquals("Control::setBounds(Rectangle) doesn't scale up correctly",
73+
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
74+
75+
button.setBounds(0, 47, 200, 47);
76+
assertEquals("Control::setBounds(int, int, int, int) doesn't scale up correctly",
77+
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
78+
}
79+
6180
private FontComparison updateFont(int scalingFactor) {
6281
Shell shell = new Shell(Display.getDefault());
6382
Control control = new Composite(shell, SWT.NONE);

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)