[Bug-11732] Perspective - Color function not returning a usable value

I attempted to bind a backgroundColor property to an expression that was just the color() expression function to quickly get a color from three values. However, this doesn’t actually make the correct color show up as the background. In the little preview color square next to the backgroundColor value (that reads ‘java.awt.Color[r=44,g=55,b=66]’), the color is correct, that just doesn’t make it to the actual background.

The red in the example there is from when I clicked the color preview square and picked red, then tried to refresh the expression binding. When put into run/preview mode, it switches to a white background, or whatever the default background color is.

This is on b2018112110. Reproduction can be done on any component, I obviously use a slider component and its backgroundColor property.

You’re very right. I’ll open a new ticket for this right now.

That expression is typically used for Vision components, which expect a java.awt.Color Object, whereas Perspective uses Hex colors throughout.

As you’re directly binding to non-interpolated (never-changing) values, consider providing the String Hex equivalent ‘#2C3742’ for the property value.

I figured, and I hope it won’t be too much to adapt it to Perspective use somehow. And that was just an example, I was testing a couple sliders making up a color for something else, but still easy to format it into the hex string like you mentioned.

As a workaround, you can add a transform if you need to use color():

	colorIn = value
	hexVal = '#' + hex(colorIn.getRed()*65536 + colorIn.getGreen()*256 + colorIn.getBlue())[2:]
	return hexVal
2 Likes