A small, subtle note from @Greg_Ođ–˝‘Lone in the thread Prepping your Xojo made Mac app for Big Sur shows that since Xojo 2019.03 we no longer need external libraries to get macOS system colors back. ColorGroups, which we already know from iOS projects, can currently only be used via code in desktop projects. And ColorGroup.NamedColor help us to use the native color values in dark/light mode in macOS desktop applications. Here is a short overview.
' The string "controlAccentColor" can be replaced by the values
' in the column "Value" in the following tables.
Var c As Color = ColorGroup.NamedColor("controlAccentColor")
Is there caching going on in the framework of these colours @Greg_Ođ–˝‘Lone? For instance, AFAIK there is a real performance cost for querying the Xojo framework IsDarkMode function in a tight loop because its value seems not be cached). Is this the same with the colours? Just wondering whether I need to be caching the values once retrieved and then only recalling the named colour method when I detect an AppearanceChanged event in the app.
Don’t cache your results in AppearanceChanged. I have an app that, IIRC, doesn’t use the event at all, and barely uses IsDarkMode. Just paint with the colors you need.
I would store the color in a variable to prevent querying in a loop, this isn’t a huge deal.
First of all, when you call ColorGroup.NamedColor, what you get back is a ColorGroup, not a Color. It’s also important to understand that ColorGroups are not “resolved” until you actually ask for the color value. That is, when you assign the obj to a value that takes a color.
So yes, if you’ve got code that looks like this:
Label1.FontColor = ColorGroup.NamedColor(“labelColor”)
Then you’ll always be pulling the color directly from the OS.
FWIW, IsDarkMode is slow because we have to trick the OS into getting the current correct system appearance every time as technically, whether you’re in dark mode isn’t valid unless you’re in a drawing context (like a canvas).