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

Text.setMessage: message text not or barely visible on all color combinations #822

Open
Wittmaxi opened this issue Sep 28, 2023 · 2 comments

Comments

@Wittmaxi
Copy link

Describe the bug
Depending on the color-combination, a message set using Text.setMessage is not visible.

To Reproduce
Snippet

Expected behavior
I either expect the message-Color to be automatically updated in such a way that it has good contrast values or I want to be able to set the message-color.

Screenshots
grafik
grafik

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    Windows 11

Version since
I'm running SWT from the master branch

Workaround (or) Additional context
I took this issue from platform.ui
Where I need this to implement my proposal filed here

basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 11, 2023
Add cache invalidation only to obvious places for now.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 13, 2023
Breadth first traversal is somewhat similar lazy TreeViewer from JFace
does on reveal - it populates a whole level of a tree, then select an
item and goes down a level.
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 18, 2023
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 18, 2023
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 18, 2023
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 18, 2023
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 19, 2023
basilevs added a commit to basilevs/eclipse.platform.swt that referenced this issue Nov 19, 2023
@HeikoKlare
Copy link
Contributor

The problem also exists on Linux, just with a slightly different color. Here a screenshot from a modified version of the snippet provided for this issue:
image

The issue seems to be that the color for the text box hint (cue) is fixed by the OS. At least for windows, I did not find a way to modify this color. Here is the documentation for setting the cue text: https://learn.microsoft.com/en-US/windows/win32/controls/em-setcuebanner

So at least on Windows it seems to be necessary to make the hint custom-drawn to better support theming. Most of the functionality is already implemented in the Text widget's processing of the WM_PAINT event for showing the message when the text widget is in read-only state:

if ((style & SWT.SINGLE) != 0 && (style & SWT.READ_ONLY) != 0 && message.length () > 0 ) {
drawMessage = hwnd != OS.GetFocus () && OS.GetWindowTextLength (handle) == 0;
}

When removing the check for read-only, the message will always be custom-drawn unless a text is set. The color applied for that custom-draw text is currently fixed:

OS.SetTextColor (hDC, OS.GetSysColor (OS.COLOR_GRAYTEXT));

But it could be calculated depending on the background color, e.g.:

int backgroundGrayValue = (getBackground().getRed() + getBackground().getBlue() + getBackground().getGreen()) / 3;
int hintGrayValue = backgroundGrayValue + (backgroundGrayValue > 128 ? -128 : 128);
Color hintColor= new Color(hintGrayValue, hintGrayValue, hintGrayValue);
OS.SetTextColor (hDC, hintColor.handle);

The example provided for the issue will then look as follows:
image

In comparison to the original:
image

For Linux and Mac, this custom logic for drawing the message does not exist. So in case there is no native way for setting the hint text color for those operating systems, some more functionality would need to be added in comparison to the Windows implementation.

However, I am not sure whether it's worth the effort to develop and maintain the custom logic, since the color only seems to be a problem with custom background colors. With standard dark theme, it looks as follows on my system:
image

@HeikoKlare
Copy link
Contributor

I've tested the behavior for the dark theme on Linux: the hint is quite well visible there
image

If it also works fine on Mac as well, just using the existing custom logic for printing the hint on Windows with a properly calculated font would be a suitable solution to solve the problem at least in the context of dark themes.

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

No branches or pull requests

2 participants