Forecolor based on back/fill color

Is there an easy way to set the text/fore color based on the current back or fill color? I thought maybe about getLuminance(), but wasn’t able to get this to work. One, can we get this property? Two, will this do me any good? I thought I could just look to see if it’s dark or light then use color map.

Any suggestions?

Might help if you stated what component you were using. :wink:

Otherwise, consider using the style customizer to drive things like color.

Right, a custom template. I feed it custom colors that come from a look up table, cell binding to styles. Since the colors are unknown, and I really don’t want to have set colors for fore and back, I was wanting to make the fore color automatic based on whether the back color was light or dark.

Found the following, https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color, it works well enough for what I need.

Have a custom property LightDark which is bound to Foreground Color and uses the simple color map.

if event.propertyName == "background":
	color = event.source.background
	r = color.getRed()
	g =  color.getGreen()
	b = color.getBlue()
	if (r*0.299 + g*0.587 + b*0.114) > 186:
		event.source.parent.LightDark = 0 #Black
	else:
		event.source.parent.LightDark = 1 #White

My issue on getLuminance() is that it’s getLightness(), was looking at wrong docs, IA support pointed that out to me. But, didn’t really need it though.