.color property on GUI controls should accept Color3 (or at least warn)

Another issue with the GUI I recently encountered was trying to give a Color3 as the .color property to a Button, which then set the text to black but left the border white (in the following example anyway, my setup was a little different):

https://www.babylonjs-playground.com/#XCPP9Y#2256

I did not get anything in the console, which is why I first thought the real bug was that it was not setting the border (wrong!).

The whole problem showed up because I had put all colors in constants, so I expected to be able to use them for the GUI too. Could we add support for that to the GUI? It doesn’t seem too hard to implement and it would be really helpful for code reuse. I am not very familar with TypeScript, so I hope it’s not a limitation from that side.

For the GUI just use the hex string:
button.color = '#fff'

Note that Color3.FromHexString() you have in your PG (that has 3 hex codes) will always return black unless you pass in 6 hex codes (total length 7):

If you want to use Color3 objects then consider toHexString().
BABYLON.Color3.FromHexString("#ffaf00").toHexString();

To be fair perhaps the library should support both of your requests, but currently doesn’t.

2 Likes

Oh thanks, so it’s in fact two bugs rolled into one. Now I remember, I have had that problem before. I’m a sucker for those CSS shorthand codes no-one else seems to use. This problem was however not present in my current project, I used a full color code there.

Yes, I think so too. At least it should say so in the docs. I posted it into the bugs forum rather than feature requests because it is somewhat counterintuitive. Babylon.js has a very rich API in general, so of course you get accustomed to that and expect it everywhere :wink:

I would even do a quick PR, but right now I’m too busy to deal with setting everything up. Maybe in a few weeks.

Please :slight_smile: All help will be appreciated

1 Like