How is a note's text color set automagically?

This is an example of tiny things in TB that delight.

I was setting the color of two notes (by setting the Color attribute). One note color is dark, the other light. I fully expected to have to later change the text color of one of these so that it stayed legible. But no – TB automatically used white text for one note and black text for the other.

What is the precise logic that controls this?

Thanks!
Abhijit

Actually, you get one of three colours:

Black text normally, or white if $Color is very dark, and in a few contrast edge cases you may get a yellow. If you set $NameColor to a local value, it overrides this automatic contrast detection.

As to the underlying calculation, you’d need to ask Eastgate.

In map view, the color of the display name is controlled by $NameColor.

The default value of $NameColor is “automatic”. If the color is automatic, we look at the $Color of the note — or, if the note is transparent, we look at $MapBackgroundColor. If the background is light (Luma > 0.7), we use black. If it’s dark (Luma<0.5), we use white. If it’s in between, we use yellow.

Luma in turn is a measure of relative luminance. It’s sqrt(.299r^2 + .587g^2 + .114*b^2), where {r,g,b} range from 0…1 . (All this is needed because a pixel that is bright green looks much brighter to us than a pixel that is bright blue.)

But if this automatic choice isn’t what you prefer, you can set the color explicitly to any color you like.

All these details may change.

2 Likes