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 FontDialog not working properly after DPI change #142

Open ShahzaibIbrahim opened 2 weeks ago

ShahzaibIbrahim commented 2 weeks ago

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

Image

Image

Test Example:

public class FontDialogExample {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("FontDialog Example");
        shell.setSize(300, 200);

        // Label to display the selected font
        Label label = new Label(shell, SWT.NONE);
        label.setText("Sample Text");
        label.setBounds(50, 50, 200, 50);

        // Button to open the FontDialog
        Button fontButton = new Button(shell, SWT.PUSH);
        fontButton.setText("Choose Font");
        fontButton.setBounds(50, 120, 100, 30);

        fontButton.addListener(SWT.Selection, event -> {
            FontDialog fontDialog = new FontDialog(shell);
            fontDialog.setText("Select Font");

            // Set default font selection
            FontData initialFont = label.getFont().getFontData()[0];
            fontDialog.setFontList(new FontData[] { initialFont });

            // Open the dialog and get the selected font data
            FontData selectedFont = fontDialog.open();
            if (selectedFont != null) {
                // Apply the selected font to the label
                Font font = new Font(display, selectedFont);
                label.setFont(font);

                // Dispose of the font when no longer needed
                shell.addListener(SWT.Dispose, e -> font.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