Skip to content

Conversation

@ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Nov 5, 2025

Enabling a consistent pattern to apply disablement or graying of an Image. They are applied whenever a handle is being created from init method. Ensuring streamline usage and avoid double calls to this method.

How to test

  • Run the Snippet382 with following VM Argument: swt.autoScale.updateOnRuntime=true
  • Move the shell between different zoom levels (100,125,150,175,200,250)
  • The snippet tests different kind of image providers to create an Image.
  • Expected result would be that we don't lose disabled or grayed image attributes.
image

Sanity test for the Cursor:

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class CustomCursorExample {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("Custom Cursor Example");
        shell.setSize(400, 300);

        // Load an image to use as the cursor
        Cursor customCursor = null;
        try {
        	ImageData imageData = new ImageData ("bin/org/eclipse/swt/snippets/eclipse16.png");
        	Image normalImage = new Image (display, imageData);
        	Image disabledImage = new Image (display, normalImage, SWT.IMAGE_DISABLE);

            Point hotspot = new Point(8, 8);

            customCursor = new Cursor(display, disabledImage.getImageData(), hotspot.x, hotspot.y);

            // Apply it to the shell
            shell.setCursor(customCursor);

        } catch (Exception e) {
            e.printStackTrace();
        }
        Label label = new Label(shell, SWT.NONE);
        label.setText("Hover here to see the custom cursor!");
        label.setBounds(50, 100, 300, 20);

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

        // Clean up resources
        if (customCursor != null) customCursor.dispose();
        display.dispose();
    }
}

The cursor should be disabled using this snippet.

@ShahzaibIbrahim
Copy link
Contributor Author

@copilot could you review it first.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Test Results

  118 files    118 suites   15m 36s ⏱️
4 651 tests 4 634 ✅ 17 💤 0 ❌
  330 runs    326 ✅  4 💤 0 ❌

Results for commit 34ea42d.

♻️ This comment has been updated with latest results.

Enabling a consistent pattern to apply disablement or graying of an
Image. They are applied whenever a handle is being created from init
method. Ensuring streamline usage and avoid double calls to this method.
@ShahzaibIbrahim ShahzaibIbrahim marked this pull request as ready for review November 5, 2025 14:37
@akoch-yatta
Copy link
Contributor

One remark: as the change seems to affect Cursor as well - Is there a Snippet/test case or could you provide one to test correctness for Cursor?

@ShahzaibIbrahim
Copy link
Contributor Author

One remark: as the change seems to affect Cursor as well - Is there a Snippet/test case or could you provide one to test correctness for Cursor?

I have added a sanity test for disabled cursor in the description.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems to currently mix up two changes: one is streamlining calls to adaptImageDataIfDisabledOrGray in the sense that there should be a common concept when to call it consistently (without any behavioral changes). Another is applying this method where it (erronoeously? on purpose?) was not applied before. The latter affects Icon-type images, for which it seems as if the adaptation was not always applied.
Can we split the PR up accordingly and, in particular, how can we see/test the changed behavior for Icon-type images?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamline calls to Image#adaptImageDataIfDisabledOrGray()

3 participants