Skip to content
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

Conversation

ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Aug 14, 2024

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:

  • Changing the text color from a grayish tone to white.
  • When ALT key is pressed mnemonics are underlined and work as a toggle, the behavior which was missing from dark theme previously.

Screenshot of the fix:

image

HOW TO TEST

  • Run the RunTimeWorkspace with the following VM Arguments
-Dswt.autoScale=quarter
-Dswt.autoScale.updateOnRuntime=true
  • Go to "Windows" -> "Preferences" -> "General" -> "Appearance"
  • Change theme to "Dark"
  • Click "Apply and Close"
  • Move the window from 100 -> 175 (or anything 100+) zoom level
  • See if menu bar is properly aligned.

SCENARIOS TESTED

autoscale.updateOnRuntime = false && autoscale=int200 (Prevent regressions)
100% (Primary), 175% (Second)
150% (Primary), 200% (Second)
175% (Primary), 125% (Second)
200% (Primary), 100% (Second)
200% (Primary), 150% (Second)
autoscale.updateOnRuntime = false && autoscale=quarter (Prevent regressions)
150% (Primary), 200% (Second)
175% (Primary), 125% (Second)
autoscale.updateOnRuntime = true && autoscale=int200
100% (Primary), 175% (Second)
150% (Primary), 200% (Second)
175% (Primary), 125% (Second)
200% (Primary), 100% (Second)
autoscale.updateOnRuntime = true && autoscale=quarter
150% (Primary), 200% (Second)
175% (Primary), 125% (Second)

EXPECTED BEHAVIOUR

The menu bar should be scaled properly.

contributes to #62 and #127

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch from 1829a6d to 2d1a006 Compare August 14, 2024 10:49
Copy link
Contributor

github-actions bot commented Aug 14, 2024

Test Results

   486 files  ±0     486 suites  ±0   8m 30s ⏱️ +53s
 4 154 tests ±0   4 146 ✅ ±0   8 💤 ±0  0 ❌ ±0 
16 370 runs  ±0  16 278 ✅ ±0  92 💤 ±0  0 ❌ ±0 

Results for commit bd3cf3a. ± Comparison against base commit 4d61d1d.

♻️ This comment has been updated with latest results.

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.

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.

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch from 2d1a006 to a9d2293 Compare August 20, 2024 13:22
@ShahzaibIbrahim ShahzaibIbrahim changed the title Drawing custom menu items for Menu Bar Drawing custom menu items for Menu Bar **Dark Theme Only** Aug 20, 2024
@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch 2 times, most recently from e7017c6 to e10a814 Compare August 21, 2024 11:21
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.

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:
image
And this is how it looks now:
image
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:
image

One additional issue I found concerns the handling of mnemonics, i.e., when pressing Alt+$ for accesing menu item with menmonic $.

  1. 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.
  2. 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.
  3. 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.

image

@HeikoKlare
Copy link
Contributor

Something seems to be wrong with the PR now. No matter whether I rebase on #1349, I see two issues:

  1. The left margin of each menu item is quite large
    image
  2. There are unexpected menu items, like another "File" entry with only a single entry in the menu that opens up from it
    image

Can you please check that, @ShahzaibIbrahim?

@HeikoKlare
Copy link
Contributor

I retested and found that the faulty second "File" entry is because of a broken workbench.xmi on my side. Still, it shows some placement issue, as the text is cut off (hapenning for a "File" entry without a mnemonic, while the original "File" entry with mnemonic is not cut off). That may be investigated. You can easily reproduce by manually adding two menus (with at least one dummy menu item in each of them to have the menu shown) through the Model Spy:
image

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch 2 times, most recently from 674c379 to 3c16e7e Compare September 5, 2024 12:10
@HeikoKlare
Copy link
Contributor

Please check your latest commit. Only considering the diff, it does not seem to be in the intended/final state. There is a System.out.println() statement and some some added magic number in addition to the essential change:
image

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch 2 times, most recently from 5ee53ab to e0d0e5b Compare September 6, 2024 08:56
@ShahzaibIbrahim
Copy link
Contributor Author

Please check your latest commit. Only considering the diff, it does not seem to be in the intended/final state. There is a System.out.println() statement and some some added magic number in addition to the essential change: image

Yes sorry, that was a leftover.

@HeikoKlare
Copy link
Contributor

I've quickly retested again, but still see the large left margin for every menu I have mentioned before. Is that intended and is it reproducible for you?
image

In addition, I see that when activating mnemonics mode (pressing Alt) only the texts but not the complete menus are highlighted. That's different to existing behavior and to behavior of the light theme. Anyway: is the behavior intended or is that by accident?
image

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch 5 times, most recently from db0f7f1 to 14830a6 Compare September 13, 2024 15:15
@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch 2 times, most recently from e197195 to 8490a8f Compare September 17, 2024 14:42
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.

Unfortunately, when doing another final testing after rebasing, I found a further issue. To reproduce, do the following:

  • Have a primary monitor with >100% scaling (e.g., 125%), have a secondary monitor with 100% scaling
  • Start an application with PerMonitorV2 DPI awareness in dark mode
  • Move the application from 125% monitor (on which it looks fine) to 100% monitor.

The sizes seem to be calculated properly, but the font is too small (probably 100% instead of 125%):
{5A84A883-8FE7-4D82-A6BC-CFAE977C2ED5}

@akoch-yatta @ShahzaibIbrahim can you please have a look? Maybe this is easy to resolve by using proper scale values at some place.

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.

Unfortunately, it looks still almost the same. On 125% it became better/good, but with the primary monitor on 150% or above, I still see the issue. E.g., this is with primary monitor 175% on secondary monitor with 100%:
{A059FDB7-CBCC-4CDD-9505-CFCA3476717E}

@akoch-yatta
Copy link
Contributor

Unfortunately, it looks still almost the same. On 125% it became better/good, but with the primary monitor on 150% or above, I still see the issue. E.g., this is with primary monitor 175% on secondary monitor with 100%: {A059FDB7-CBCC-4CDD-9505-CFCA3476717E}

@HeikoKlare Sorry for all that back and forth, we need to improve the test protocol on our side, so you don't have that much work retesting changes. It is not yet properly working on all scenarios, as you mentioned. We'll have a look on that tomorrow.

@HeikoKlare
Copy link
Contributor

This is how it looks when I start on 125%:
{CF47A728-DFE2-4A9B-B158-DCEE972EED02}

This is on 150%:
{35FDDA79-378F-47AF-AF7A-64C9D3E879E4}

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch 5 times, most recently from b1bbcd6 to 2fe01bf Compare October 9, 2024 10:50
@akoch-yatta
Copy link
Contributor

In each of the following screenshot there is an adapted version of Snippet373 started with commit 2fe01bf, 4 times each. The title gives the info of the configuration:

  1. autoscaleOnRuntime active or not
  2. autoscale mode: int200 or quarter

Setup: Primary 125%, secondary 175%
Primary:
image
Secondary:
image


Setup: Primary 175%, secondary 125%
Primary:
image
Secondary:
image


Setup: Primary 150%, secondary 200%
Primary:
image
Secondary:
image


Setup: Primary 200%, secondary 100%
Primary:
image
Secondary:
image

@HeikoKlare
Copy link
Contributor

HeikoKlare commented Oct 11, 2024

Is this supposed to be ready for another review? I have only taken a quick look into an SDK application, but horizontal spacing is still off. See this screenshot at 150% (top one is with current implementation, bottom one with this PR):
{124AEFF1-853E-4512-8926-1BB6DCFECDCC}

And at 175%/200%, vertical spacing also seems broken (scaling mode "integer200"):
{8F80122D-F1D4-46ED-A55A-A77BD6127C12}

@akoch-yatta akoch-yatta force-pushed the use-dpi-dependent-win32-api-calls branch from 347ffb3 to cd3bb9b Compare October 11, 2024 12:53
@akoch-yatta
Copy link
Contributor

Hmm, I cannot reproduce any vertical spacing issue, neither with quarter nor with int200.
100%
image
150%
image
175%
image
200%
image

Regarding the horizontal indentation: I agree, that int direct comparision positioning could be improved. I tweaked some statics in cd3bb9b to achieve the following result
100%
image
150%
image
200%
image

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

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

The changes look fine to me and I didn't find any regressions/bugs while testing.

I only have 2 nit-picky comments regarding readability but aside from that, this PR is good to go on my account.

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

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

@ShahzaibIbrahim please squash your commits and this one is good to go on my account. @HeikoKlare should I merge or do you want to take another look?

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.

I've retested this and did not find any issues anymore. In particular with existing HiDPI support (i.e., without per-monitor rescaling at runtime) and all combinations of settings (integer200 or quarter scaling, DPI awareness set to PerMonitorV2 or System, two monitors with different scalings between 100% and 200%).

The general appearance is also better than with the existing implementation (placement/spacing and highlight color). There is still some room for slight improvements on vertical alignment (with 100% is slightly off to the top while at 175% it is slightly off to the bottom), but that's rather nitpicky and, as said, the proposed state is still far better than the existing one.

@ShahzaibIbrahim can you please check the code formatting again (see, e.g., the comments I made) and squash the commits, so that we can merge this for M2?

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch 3 times, most recently from 885fc63 to c895e4f Compare October 15, 2024 08:48
@ShahzaibIbrahim ShahzaibIbrahim force-pushed the use-dpi-dependent-win32-api-calls branch 2 times, most recently from 2a88c65 to 5ba361d Compare October 15, 2024 08:56
@fedejeanne
Copy link
Contributor

fedejeanne commented Oct 15, 2024

I would like to merge this PR but I'm not sure that every check ran. I only see 7 on the Checks tab.

image

Other PRs have also checks from Jenkins

image

I also noticed that https://ci.eclipse.org/releng is currently offline

image

Is there a shortage outage? @merks / @laeubi / @akurtakov ?

@HeikoKlare
Copy link
Contributor

Is there a shortage?

https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/issues/5131

@BeckerWdf
Copy link
Contributor

Is there a shortage?

you mean "outage"?

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.
@HeikoKlare HeikoKlare force-pushed the use-dpi-dependent-win32-api-calls branch from 5ba361d to bd3cf3a Compare October 15, 2024 12:18
@HeikoKlare
Copy link
Contributor

Jenkins is still unavailable, but (Jenkins) builds before latest update were successful and without new issues. Since only formatting changes have been performed since then, this is still safe to merge.

@HeikoKlare HeikoKlare merged commit 30f11e9 into eclipse-platform:master Oct 15, 2024
8 checks passed
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.

6 participants