Recent

Author Topic: Memo highlighting colour & contrast issue  (Read 284 times)

trev

  • Full Member
  • ***
  • Posts: 212
  • Former Delphi 7 and Delphi 10.2 User
Memo highlighting colour & contrast issue
« on: June 30, 2019, 05:48:17 am »
When highlighting a search hit in a memo, rather than the usual light blue highlight colour, the highlight is colour light grey. This is just usable in light mode on macOS, but in dark mode the highlighting simply disappears into the background.

Attachment 1: light mode
Attachment2: dark mode

Can the colour of the highlighting be changed?
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

lucamar

  • Hero Member
  • *****
  • Posts: 2023
Re: Memo highlighting colour & contrast issue
« Reply #1 on: June 30, 2019, 06:04:42 am »
It is not exactly that the "highlight"-color changes but that the memo is not the focused control.

When an edit control (or, in fact, most controls) goes out of focus the color of the selection is "washed out" as a visual cue. This happens in virtuallly all OS/WM combinations.

You can test this yourself: simply <TAB> back and forth from the edit control to the memo to see the selection's color change.

AFAIK the only way to avoid it is to modify the Window Manager theme by hand, which I don't know how is done in MacOS, but I suppose you do?
« Last Edit: June 30, 2019, 06:06:40 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

trev

  • Full Member
  • ***
  • Posts: 212
  • Former Delphi 7 and Delphi 10.2 User
Re: Memo highlighting colour & contrast issue
« Reply #2 on: June 30, 2019, 06:25:31 am »
Curiously it doesn't happen in Windows 7 or 10 (same code) -- see attachment.

It also didn't happen in the old Delphi 10.2.1 version of my program in Windows or macOS which led me to believe it was Lazarus/FPC thing and possibly related to the Cocoa widget set because it doesn't happen in Windows with the win32 widget set.

Quote
You can test this yourself: simply <TAB> back and forth from the edit control to the memo to see the selection's color change.

Yep, I noticed that.

Quote
AFAIK the only way to avoid it is to modify the Window Manager theme by hand, which I don't know how is done in MacOS, but I suppose you do?

Alas, I don't. However, it just occurred to me that maybe I can get away with leaving the focus on the memo and capturing the keystrokes, filling in the search edit and all will be well. Hmmm.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2268
    • havefunsoft.com
Re: Memo highlighting colour & contrast issue
« Reply #3 on: June 30, 2019, 06:29:57 am »
When highlighting a search hit in a memo, rather than the usual light blue highlight colour, the highlight is colour light grey. This is just usable in light mode on macOS, but in dark mode the highlighting simply disappears into the background.
This is by Apple design. Cocoa widgetset doesn't modify the selection color in anyway.
In your case the issue is seen when TMemo doesn't have a focus.

Try the following - start Apple's TextEdit, paste the same text and you have on the screenshot.
Select the text (note that "focused" control selection is blueish)
and then click away from TextEdit (to make it non focused window).
You should see that Apple's TextEdit selection color is exactly the same as TMemo's color.

Can the colour of the highlighting be changed?
The answer is maybe. There are some methods in NStextView that could be overridden or property to be changed (i.e. https://developer.apple.com/documentation/appkit/nstextview/3237223-usesadaptivecolormappingfordarka?language=objc)
In the end, even there's a solution, it would be macOS specific.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

lucamar

  • Hero Member
  • *****
  • Posts: 2023
Re: Memo highlighting colour & contrast issue
« Reply #4 on: June 30, 2019, 06:33:41 am »
[..] it just occurred to me that maybe I can get away with leaving the focus on the memo and capturing the keystrokes, filling in the search edit and all will be well. Hmmm.

That is ... not recommended. Instead, move the focus back to the memo after setting the selection. To keep on searching just add a handler for the memo's OnKeyUp event capturing F3 or whatever key(s) and, if needed (v.g. to start a new search) moving the focus again to the TEdit.

Curiously it doesn't happen in Windows 7 or 10 (same code) -- see attachment.

[...] it doesn't happen in Windows with the win32 widget set.

Hmm ... you may be right. IIRC Windows just does an all-or-nothing when the control is not focused (depending on some option whose name scapes me ATM): either shows the selection normally or not at all. Linux WMs, on the other hand, act like MacOS in this respect.
« Last Edit: June 30, 2019, 06:39:23 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

trev

  • Full Member
  • ***
  • Posts: 212
  • Former Delphi 7 and Delphi 10.2 User
Re: Memo highlighting colour & contrast issue
« Reply #5 on: June 30, 2019, 06:53:10 am »
Thanks Dmitry and lucamar. I'll look into my options.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)