-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Description
Control#getBoundsInPixels and Control#getSize have an inconsistent way to calculate its value. Control#getBoundsInPixels takes x/y into consideration to scale down from px to pt, Control#getSize. This can lead to different values for width and/or height for the same px value.
Reproduction
Execute the Snippet below with a primary monitor on 125% and you see the following output:
Bounds height 201
Size height 202
So, getBounds
says the height is 201pt, but getSize
claims it to be 202pt
package org.eclipse.swt.snippets;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Snippet385 {
public static void main (String [] args) {
final Display display = new Display ();
final Shell shell = new Shell (display);
shell.setText("Snippet385");
Composite composite = new Composite(shell, SWT.None);
List list = new List(composite, SWT.NONE);
list.add("List item 1 with a very very long name and no end");
composite.setBounds(0, 0, 250, 250);
list.setBounds(0, 49, 250, 201);
Rectangle bounds = list.getBounds();
Point size = list.getSize();
if (bounds.height != size.y) {
System.out.println("Bounds height " + bounds.height);
System.out.println("Size height " + size.y);
}
shell.setSize(400, 750);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Expected Behavior
Control#getBoundsInPixels and Control#getSize should always return the same values regarding width and height
Necessary configuration:
Primary monitor on 125% for the Snippet
Also need to set -Dswt.autoScale=quarter
Additional knowledge
Fix for this could be to use getBoundsInPixels instead of getSizeInPixels and scale width and height of it down.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status