vi-eclipse / Eclipse-Platform

Umbrella repository for managing a backlog of features/issues related to the Eclipse Platform
2 stars 0 forks source link

Scaling of ColorDialog not working properly after DPI change #141

Open ShahzaibIbrahim opened 2 weeks ago

ShahzaibIbrahim commented 2 weeks ago

Scaling of ColorDialog breaks during dpi change. In this screenshot, it is 100 -> 150

Image

Image

Test Example:

public class ColorDialogTest {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("ColorDialog Example");
        shell.setSize(300, 200);
        GridData data = new GridData(GridData.FILL_BOTH);
        shell.setLayoutData(data);
        // Create a button to open the color dialog
        Button button = new Button(shell, SWT.PUSH);
        button.setText("Choose Color");
        button.setBounds(50, 50, 100, 30);

        // Add a listener to open the ColorDialog when button is clicked
        button.addListener(SWT.Selection, event -> {
            ColorDialog colorDialog = new ColorDialog(shell, SWT.APPLICATION_MODAL);
            colorDialog.setText("Select a Color");

            // Open the dialog and get the selected color
            RGB selectedColor = colorDialog.open();

            if (selectedColor != null) {
                // Apply the selected color as the shell background
                Color color = new Color(display, selectedColor);
                shell.setBackground(color);

                // Dispose of the color when done
                shell.addListener(SWT.Dispose, e -> color.dispose());
            }
        });

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }

Run the example with the following VM Arguments

-Dswt.autoScale=quarter
-Dswt.autoScale.updateOnRuntime=true