LCLCOCOA: Draw text using NSColor constants to fix disabled TLabel
Original Reporter info from Mantis: zpeterson @boramis
-
Reporter name: Zoë Peterson
Original Reporter info from Mantis: zpeterson @boramis
- Reporter name: Zoë Peterson
Description:
This patch makes two changes:
-
Turn on ThemeServices.ThemesEnabled for Cocoa
-
Text painting now uses original alpha transparent NSColors for system colors like clGrayText rather than converting to RGB with a flattened alpha
The primary purpose of the changes is to make disabled TLabel draw using NSColor.disabledControlTextColor so it looks the same as other disabled controls like TCheckbox when it's drawn in dark mode. See the attached screenshot.
The patch itself is large, but most of it is moving things around. SysColorToNSColor is moved from cocoawinapi.inc to cocoautils.pas, which necessitated moving the various IsDark* routines there from CocoaThemes as well. The core of the patch is:
-
Enabling TCocoaThemeServices.InitThemes, UseThemes, and ThemedControlsEnabled, which makes TThemeServices.ThemesEnabled return true, which makes TCustomLabel.Paint use clGrayText for painting instead of the etched appearance. That change alone makes the drawing go from the first to second variant in the attached screenshot.
-
TCocoaContext.SetTextColor maintains the incoming TColor rather than immediately converting it to an RGB value, and then TCocoaTextLayout.UpdateColor tries to convert to a known NSColor before doing the ColorToRGB calls. That makes the drawing go from the second variant to the third one, which matches the disabled TCheckbox.
-
TCocoaWidgetSet.GetTextColor uses ColorToRGB to convert the stored one to RGB before returning it so places that expect it to be a COLORREF get it correctly. It's done there instead of TCocoaContext.GetTextColor so TCocoaContext.SaveDCData/RestoreDCData aren't lossy.
Steps to reproduce:
- Create a new LCLCOCOA application
- Add a TLabel and a TCheckbox to the form and set both of their Enabled properties too False.
- Run the application with the system appearance set to "Dark"
With the above, the label and checkbox text will be different colors. With the patch they appear identical. Screenshot taken on macOS 10.14.6 Mojave.
Mantis conversion info:
- Mantis ID: 38280
- Version: 2.0.10
- Fixed in revision: 64452 (#b1a7028c)