-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Windows 11] MenuItem with style SWT.CHECK and image doesn't show state #501
Comments
The screenshot above shows a difference between
It seems that on Win11, theme decided to no longer paint blue square around the icon, hence the difference. I would say that the other problem here is that the image is always painted, whether checked or not. |
Isn't that the expected behaviour? |
Looking at the default check mark (in regular |
Conclusions: Windows theming issue, not an SWT bug. |
If so, should we close this? |
Probably. |
Closing... |
What does that mean? You mean it's a bug of Windows? |
It's hard to say if it's a "bug" or "design decision". SWT relies on how Windows styled things, but Windows decided to style it differently in Win11. Will that decision be reverted in Win11? Who knows |
Could we "work around" this in SWT? Or can we open a bug report at MS? |
It should be easy to work around (not perfectly, but good enough) using this (partly) pseudo-code final int margin = getDpiScalingFactor(display);
final Rectangle size = image.getBounds();
final Image selectedImage = new Image(image.getDevice(), size.width + 2 * margin, size.height + 2 * margin);
final GC gc = new GC(selectedImage);
try {
final Color background = createBlendedColor(image.getDevice().getSystemColor(SWT.COLOR_LIST_BACKGROUND),
image.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION), 0.25);
gc.setBackground(background);
gc.fillRectangle(0, 0, size.width + 2 * margin, size.height + 2 * margin);
gc.drawImage(image, margin, margin);
}
finally {
gc.dispose();
} |
It is very easy to say that this is a bug! Even if you like to call it "design decision" to hide important information, it is still a bug. For example in the junit view it is not possible to see any more which layout (horizontally, vertically or automatically) is currently applied. |
Are you able to provide a solution and pull request? |
Maybe you misunderstood Alex. He told that the problem occurs with pure native code, too, so this is no bug in SWT, but rather in Windows (if Microsoft not intentionally changed this). You need to send your request for a solution to Microsoft! Alternatively, SWT is open source - please feel free to send a pull request with the solution. |
One thing is for sure: There is a bug in Eclipse! And this is independent from the fact if I send a pull request or not! |
What part of "this is no bug in SWT, but rather in Windows" do you not understand? |
Well, I understand that, but it doesn't help. Because most probably it won't be fixed by Windows and then the bug will stay in many eclipse views. And this is a major problem. Or do you have a different opinion? |
If this is how it is because of a change in Windows 11, as @SyntevoAlex explains above, then you're out of luck. However, if you want to implement a workaround then I suggest to follow the suggested code hint from @tmssngr in the comment above. |
Can we put this into SWT? I understand that this is a bug or design decision of MS but I also see that Eclipse (and other SWT-based apps really have an issue with it. So I think it's work to fix this in SWT. |
As there is an active interest in this issue, let's re-open it so it's visible. |
I don’t think anybody will care whose fault the problem is. If I can’t tell whether a menu item in my Eclipse application is checked or not then my perception will be that it’s a bug and a really bad one at that. We could tell 100,000 users it’s someone else’s fault but do we want to tell them we can’t do anything about it? Or worse that we don’t want to do anything about it. Of course it’s free so no one is obligated to do anything. |
It turns out that some of my images are not centred in themselves, even though they're the same size. Try this snippet: import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
public class MenuImageTest {
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Menu Image Test");
shell.setBounds(200, 200, 200, 200);
Menu appMenuBar = display.getMenuBar();
if(appMenuBar == null) {
appMenuBar = new Menu(shell, SWT.BAR);
shell.setMenuBar(appMenuBar);
}
MenuItem file = new MenuItem(appMenuBar, SWT.CASCADE);
file.setText("File");
Menu dropdown = new Menu(appMenuBar);
file.setMenu(dropdown);
Image image = new Image(display, MenuImageTest.class.getResourceAsStream("image.png"));
for(int i = 0; i < 6; i++) {
MenuItem m = new MenuItem(dropdown, SWT.CHECK);
m.setImage(image);
m.setText("Test Menu");
m.setSelection(true);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
} With this Now gives this result, unchecked and checked: |
@Phillipus any chance to post a screenshot good / bad to see the difference? |
So the approach works fine and has now apparent problems? |
Problems I see:
|
This doesn't sound like a problem to me.
Just add a few pixels in eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java Lines 1175 to 1178 in 7d58a7d
|
Compared with current state (no indication of checked state at all) we probably should accept the problems. |
That's how it works on Mac. |
As it's a Windows 11 issue, Windows 10 users might not like the change. |
The change in code can be guarded with |
Also, this code should only be enabled if a menu has items with both SWT.CHECK and an image. |
@SyntevoAlex : would you please push a patch we can check? |
I think my boss will complain if I do :) |
It looked bad when my images were not aligned. Using the same image it's better. It now needs a couple more pixels margin between the image and the text. |
Maybe it would be better to figure out how to draw the (blue) highlight around the checked image, as it's done now in Windows 10. If it had worked like that from the get go in 11, this would not be an issue. |
Have we found any acceptable resolution for this? I would like to hear it as this relates to my issue: https://github.com/vi-eclipse/Eclipse-JDT/issues/15 |
Sorry, no. I have not had time to work on this, despite good intentions to do so. I'm still on Windows 10 so I still avoid the issue. 😱 |
@ShahzaibIbrahim: maybe a workaround would help you for the moment?
|
Is there any plan to fix the issue in June 2024? When more customers are starting to use Windows 11, this issue causes a lot of confusion as no indicator shows menu is selected or not |
This is an open source project and every change can be moved forward by contributing a fix. |
Windows 11
Eclipse 4.26
Run this Snippet on Windows 10 and Window 11 and compare the drop down menu after selecting it:
Use an image for
image.png
such as:On Windows 10 selected state looks like this:
In Windows 11 selected state looks like this:
The text was updated successfully, but these errors were encountered: