-
Notifications
You must be signed in to change notification settings - Fork 132
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
Drawing custom menu items for Menu Bar **Dark Theme Only** #1405
base: master
Are you sure you want to change the base?
Drawing custom menu items for Menu Bar **Dark Theme Only** #1405
Conversation
1829a6d
to
2d1a006
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the changes with different scale factors and auto-scale settings (quarter/integer200). The scaling results look fine, in constrast to the existing scaling behavior that was broken.
I have some detailed comments and a general question: are there snippets to test the behavior also in combination with images? Our default applications only have menus with text but it would also be interested to test the changes with images, so we should either have or provide a snippet with images for validation.
Please also improve the commit message according to the recommendations, such that it explains the existing issue and more precisely describes the fix. E.g., it currently sounds as if the menu is always draw in a custom way by this change, but it only affects the behavior when using dark theme.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Outdated
Show resolved
Hide resolved
2d1a006
to
a9d2293
Compare
e7017c6
to
e10a814
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the recent improvements. There are several improvements in the new version, that's great. In particular, this change also improves the visualization of menus with images. This is how it looked before:
And this is how it looks now:
Only problem is that the left margin is always applied to the text, even if an image is present. But in that case, the margin should be applied to the image (and maybe some additional small margin needs to be placed beetween image and text). This is, e.g., how it looks for the light theme:
One additional issue I found concerns the handling of mnemonics, i.e., when pressing Alt+$ for accesing menu item with menmonic $.
- The visualization is broken: the background color of the menu items does not fit when pressing the "Alt" button (it is black while the rest of the menu is grayish). See the screenshot below.
- Mnemonics are always displayed (underlined) and not only when Alt is pressed. This is, actually, existing behvior, but differs from default behavior, such as in light theme, where the mnemonics are only underlined when Alt is pressed. Maybe we could address this as a follow up, as no regression is introduced. On the contrary, in the current behavior, pressing Alt hides the mnemonics, so badly inverts the intended behavior.
- Most severe issue: there is no reaction to key bindings for mnemonics. E.g., pressing Alt+F should open the "File" menu, but does nothing.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
Outdated
Show resolved
Hide resolved
9949dbc
to
3d1c1ce
Compare
Something seems to be wrong with the PR now. No matter whether I rebase on #1349, I see two issues:
Can you please check that, @ShahzaibIbrahim? |
674c379
to
3c16e7e
Compare
5ee53ab
to
e0d0e5b
Compare
db0f7f1
to
14830a6
Compare
14830a6
to
e197195
Compare
When switched to Dark Theme, using gc to draw menu item, moving the responsibility from OS due to wrong scaling of menu bar vertically. Also changing the text color from a grayish tone to white. Also when ALT key is pressed mnemonics are underlined and work as a toggle, the behavior which was missing from dark theme previously.
e197195
to
8490a8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed change works really great now! It fixes the existing issues with scaling the menu bar in dark theme and it also improves the appearance of the menu bar in dark theme overall.
I only have one behavioral concern left, which is about the statically defined margins that (1) seem to be inappropriate and (2) are scaled incorrectly. The other comments are regarding code style / design and rather nitpicky.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Outdated
Show resolved
Hide resolved
/* | ||
* Weirdness in Windows. Setting `HBMMENU_CALLBACK` causes | ||
* item sizes to mean something else. It seems that it is | ||
* the size of left margin before the text. At the same time, | ||
* if menu item has a mnemonic, it's always drawn at a fixed | ||
* position. I have tested on Win7, Win8.1, Win10 and found | ||
* that value of 5 works well in matching text to mnemonic. | ||
* NOTE: autoScaleUpUsingNativeDPI() is used to avoid problems | ||
* with applications that disable automatic scaling. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this relevant anymore, so that the width can be set to a different value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This information still seems relevant on explaining the difference between left margin
and item size
. Also we are back to using value of 5 again to match the margins between items in menu bar. I would suggest to keep this comment as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, then please re-add it, because currently this PR will remove it. Only the information on autoScaleUpUsingNativeDPI should be revised, as that method is not used anymore.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
Outdated
Show resolved
Hide resolved
final static int LEFT_TEXT_MARGIN = 15; | ||
final static int ADDED_ITEM_WIDTH = 15; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are these values derived? The margins look rather different to the existing implementation and to the light theme. In the existing implementation, a value of "5" was hardcoded for the left margin at some point, maybe that would fit as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going back to the value 5 for item width as before (because of larger gap) and left margin value was derived as a result of testing against different values and finding out the closest to the light theme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code quality improvements are overall fine. The behavioral concerns in the last review have not been addressed yet. Please check them again.
In addition, testing Snippet 373 shows a misplacement of the image:
One minor finding that may be addressed independently as it is not part of this PR:
the image is not scaled correctly when using rescaleOnRuntime
:
/* | ||
* Weirdness in Windows. Setting `HBMMENU_CALLBACK` causes | ||
* item sizes to mean something else. It seems that it is | ||
* the size of left margin before the text. At the same time, | ||
* if menu item has a mnemonic, it's always drawn at a fixed | ||
* position. I have tested on Win7, Win8.1, Win10 and found | ||
* that value of 5 works well in matching text to mnemonic. | ||
* NOTE: autoScaleUpUsingNativeDPI() is used to avoid problems | ||
* with applications that disable automatic scaling. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, then please re-add it, because currently this PR will remove it. Only the information on autoScaleUpUsingNativeDPI should be revised, as that method is not used anymore.
gc.setBackground(isSelected? display.getSystemColor(SWT.COLOR_DARK_GRAY) : parent.getBackground()); | ||
gc.fillRectangle(menuItemArea); | ||
|
||
int xPoisitonText = DPIUtil.scaleDown(x + LEFT_TEXT_MARGIN, zoom) + (this.image != null ? this.image.getBounds().width : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also fix the typo in the variable name xPoisitionText
Using gc to draw menu item, moving the responsibility from OS due to wrong scaling of menu bar horizontally in Dark Theme. Snippet 373 can be used to test menuItems with images.
Additional points covered in this PR:
Screenshot of the fix:
HOW TO TEST
RunTimeWorkspace
with the following VM ArgumentsEXPECTED BEHAVIOUR
The menu bar should be scaled properly.
contributes to #62 and #127