toga icon indicating copy to clipboard operation
toga copied to clipboard

Conditional Colorization based on Dark Mode State

Open johnzhou721 opened this issue 4 months ago • 5 comments

What is the problem or limitation you are having?

Some platforms the UI dark/light can autochange based on something like time, so we need to probably implement something similar to a "color set" specifying different colors to display under dark/light mode differently, and have it automatically switch using native APIs.

Describe the solution you'd like

See above

Describe alternatives you've considered

Using a handler for users to change all colors manually; if there's a huge bunch of colors, maybe won't work so well.

Additional context

https://github.com/beeware/toga/issues/2841#issuecomment-3190224719

johnzhou721 avatar Aug 14 '25 23:08 johnzhou721

Also closely related: #2842

HalfWhitt avatar Aug 15 '25 00:08 HalfWhitt

I don't think #2842 is quite the same. That issue is about "I have this shade of red; give me the same color, but 25% lighter". This issue is about providing an equivalent of the CSS @media (prefers-color-scheme: dark) directive.

freakboy3742 avatar Aug 15 '25 00:08 freakboy3742

No, not the same, although I'd imagine that one can actually maybe generate alternative colors for dark mode using a heuristic if people are too lazy to encode their own alternative colors.

johnzhou721 avatar Aug 15 '25 00:08 johnzhou721

No, not the same, although I'd imagine that one can actually maybe generate alternative colors for dark mode using a heuristic if people are too lazy to encode their own alternative colors.

I was also thinking that while the simplest execution of a dark-mode-aware "less emphasized" or "more emphasized" modifier would be to perform its calculation based on the current mode and spit out a plain, precomputed Color instance... it could be very useful if there were a way to keep track of the color it's based on, and which "direction" it's supposed to go, and then update its displayed value if and when the app's dark/light mode changes.

HalfWhitt avatar Aug 15 '25 04:08 HalfWhitt

Hrm... maybe... but what little I know of color spaces suggests the problem is a lot more complex than "invert a brightness attribute in a HSL definition".

freakboy3742 avatar Aug 15 '25 07:08 freakboy3742