Get RGBA Text from Color Datatype?

I’m sure I’m missing something obvious here, but we are building an admin interface to allow customization of app configuration parameters, including colors.

We understand how to use functions to get a color from text, but what is the function to get the RGBA text from a color datatype (variable or table data)?

TOTEXT() doesn’t let me wrap a color datatype variable, nor does the Copy to Clipboard action.
I don’t see any TEXTTOCOLOR() option.
The closest I’ve got is to display the color as a message:
image

@giladl this is the issue I described at Office Hours this morning.

I believe the issue is that there is no direct function to convert a Color datatype into text. The Color type is its own variable type in Tulip, so TOTEXT cannot take it as input.

To output the color value as text, I think you can reference the channel values and build the string manually. Try something like

“r:” + @MyColor.r + “, g:” + @MyColor.g + “, b:” + @MyColor.b + “, a:” + @MyColor.a

If you also want the color to be configurable, one common pattern is to store it as text (hex or RGBA) and then convert that text to a Color only when applying it to the widget.

Can you clarify what you mean by "reference the channel values? Color variables won’t even show up in the expression editor so my guess is you mean to have text variables representing each RGB() expression argument.

Another thing I noticed, if you have the color in a table and export as CSV, you can get the RGBA values:


Hi @jmlowden,

Thanks for checking that. I just tried it myself and you are right. Color variables do not show up in the expression editor, so you cannot break them out into r, g, b, a values. That was on me earlier. Thanks for calling it out.

As far as I can tell, Tulip does not currently have a built-in way to convert a Color type back into text (RGBA or hex). TOTEXT does not accept Color, which is why you were running into the limitation.

The pattern I usually see for editable color settings is:

• Store the color as text (hex or something like “255,128,0,1”)
• Convert that text to a Color only when applying it to a widget using RGB()

This way you keep the value human-readable for the admin UI while still using the Color type for styling.

Also, the CSV export behavior you found is real and is actually a useful workaround when you need to extract a color value in text form. Nice catch.

If you’d like, I can pass this along as a feature request for adding a direct Color → Text function.

Hi @jmlowden

there seems not to be an expected way to solve this.

a dirty workaround is to push it to an array and get the value by editor:

1 value only:

2 whole array:

2 Likes

That will work! Thanks for taking the time to suss this out!

Thinking about this more generically, it would be good if there were more comprehensive symmetry or parity for casting data types back and forth - also if the casting expressions could accept alternative formats for the input arguments, such as the RGA() expression being able to take the current input, but also recognize and internally parse the above string.

Besides color, I’m wondering if there are any other opportunities to close up gaps in casting expressions.

Hi @jmlowden and @thorsten.langner. You are right that Color variables do not expose r, g, b, an and there is no Color to Text cast. For config, store the color as text (hex or “r,g,b,a”) and convert with RGB() only when styling. If you already have a Color, Thorsten’s array trick or a table row with CSV export can surface a text value. This would be smoother with Color to Text, Text to Color that accepts hex or “r,g,b,a,” and RGB() that can parse a single string. If you want, post this in Product Suggestions, it helps the dev team gauge community engagement with any ideas.

1 Like