Getting a ColorGroup's light and dark colours

I have been using the new ColorGroup class in a desktop project and it works great. All instances are in “dual colour” mode (i.e. are instantiated with a light and dark colour):

Var cg As New ColorGroup(LIGHT_COLOR, DARK_COLOR)

After instantiation, is there any way to get the light and dark colours from the ColorGroup instance? I can see there is a ColorGroup.Values method that returns an array of Color objects. Is the order of this array predictable? For instance, is Values(0) always the light mode colour and Values(1) always the dark mode colour?

Var cg As New ColorGroup(LIGHT_COLOR, DARK_COLOR)
Var values() As Color = cg.Values
Var light As Color = values(0) // Is this always the light colour?
Var dark As Color = values(1) // Is this always the dark colour?

I understand that the “correct” colour is returned by the ColorGroup object when used in place of a Color object but I am writing a theme system and need access to the light and dark mode colours regardless of the current macOS light or dark mode status.

While that may work for colors that you create, it will not work for system colors. Those are only available from the system when in those modes and on macOS and iOS they change based on user preferences. For instance, the user accent color is used to tint four other colors on macOS 10.14 and 10.15.

1 Like

Can I guarantee that it will work for colours I create?

Is it worth a feedback request to be able to retrieve a specific light/dark colour?

I peeked at the code last night and at the moment it will return the entire contents that you put in. That said, this will only work if the only thing you put in is a dual color.

ColorGroups were designed to be cross-platform in the long run, behaving like a functional constant in many ways, so that you could create one color object to be used in your desktop and mobile projects and it would “just work”. For instance, let’s say that you are working on a cross platform desktop project. You decide to use systemRed on macOS so the color isn’t too bright in dark mode Well, macOS named colors don’t work in Windows or Linux, so you could add a default color fallback with an appropriate color just for them.