Skip to content

[GTK][HiDPI] Disabled Button and ImageGcDrawer gives wrong image and scale #3142

@Phillipus

Description

@Phillipus

Linux Mint (X11) and Ubuntu (Wayland) latest versions
Hi-res display (200% scaling)
Latest SWT I-builds

A common color chooser widget is a Button with an image consisting of a color block denoting the current color. Our RCP app uses such a color chooser. However, a combination of the following leads to a bad result:

  • Linux
  • 200% display scaling
  • ImageGcDrawer
  • Button disabled

Run the snippet below and comment out the line button.setEnabled(false);. It should look like this:

Image

Now add the line back to disable the button. It looks like this:

Image
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class LinuxButtonImageDrawer {
    
    public static void main(String[] args) {
        final Display display = new Display();

        final Shell shell = new Shell(display);
        shell.setText("Linux Button Image");
        shell.setLayout(new GridLayout());
        shell.setSize(450, 250);
        
        Button button = new Button(shell, SWT.FLAT);
        
        ImageGcDrawer gcDrawer = (gc, width, height) -> {
            gc.setBackground(new Color(255, 200, 255));
            gc.fillRectangle(0, 0, width - 1, height - 1);
            gc.drawRectangle(0, 0, width - 1, height - 1);
        };
        
        Image image = new Image(display, gcDrawer, 40, 15);
        button.setImage(image);
        
        // Setting this to false causes the problem
        button.setEnabled(false);
        
        shell.open();

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

        display.dispose();
    }
}

The following example in Eclipse's preferences might be related:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions