Skip to content

[win32] Unify scaling inside Control::setBounds #1769

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenario() {
fontComparison.originalFontHeight, fontComparison.currentFontHeight);
}

@Test
public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {
DPIUtil.setMonitorSpecificScaling(true);
Display display = Display.getDefault();
Shell shell = new Shell(display);
DPITestUtil.changeDPIZoom(shell, 175);

Button button = new Button(shell, SWT.PUSH);
button.setText("Widget Test");
button.setBounds(new Rectangle(0, 47, 200, 47));
shell.open();
assertEquals("Control::setBounds(Rectangle) doesn't scale up correctly",
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());

button.setBounds(0, 47, 200, 47);
assertEquals("Control::setBounds(int, int, int, int) doesn't scale up correctly",
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
}

record FontComparison(int originalFontHeight, int currentFontHeight) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3168,13 +3168,7 @@ void setBackgroundPixel (int pixel) {
* </ul>
*/
public void setBounds(int x, int y, int width, int height) {
checkWidget ();
int zoom = getZoom();
x = DPIUtil.scaleUp(x, zoom);
y = DPIUtil.scaleUp(y, zoom);
width = DPIUtil.scaleUp(width, zoom);
height = DPIUtil.scaleUp(height, zoom);
setBoundsInPixels(x, y, width, height);
setBounds(new Rectangle(x, y, width, height));
}

void setBoundsInPixels (int x, int y, int width, int height) {
Expand Down
Loading