Converting a Color object to its string representation
Eran Leshem
eran at leshem.life
Mon Dec 11 21:17:59 UTC 2023
Thank you for your responses.
Given that the framework requires colors in string format in its style APIs, I think it should provide some way to convert colors to strings as expected by these APIs. Otherwise, clients are forced to implement this bridging logic on their own, due to a framework gap.
And given that Color already parses these string representations, I think it makes sense for it to provide the inverse conversion.
Eran
-----Original Message-----
From: openjfx-dev [mailto:openjfx-dev-retn at openjdk.org] On Behalf Of John Hendrikx
Sent: Saturday, December 09, 2023 11:35 PM
To: openjfx-dev at openjdk.org
Subject: Re: Converting a Color object to its string representation
I think this is too niche to have Color provide.
Just make a utility method for whatever format you desire, instead of
making Color responsible for half a dozen ways of formatting colors, and
then probably still missing some format that someone needs.
Ticket should be closed as won't fix.
--John
On 09/12/2023 22:06, Michael Strauß wrote:
> I obviously meant to write withPrefix("#"), not withDelimiter("#")...
>
> On Sat, Dec 9, 2023 at 9:57 PM Michael Strauß <michaelstrau2 at gmail.com> wrote:
>> How would HexFormat work with Color, other than using an extremely
>> unwieldy syntax?
>>
>> String formatted = HexFormat.of()
>> .withDelimiter("#")
>> .formatHex(new byte[] {
>> (byte)(color.getRed() * 255.0f),
>> (byte)(color.getGreen() * 255.0f),
>> (byte)(color.getBlue() * 255.0f),
>> (byte)(color.getOpacity() * 255.0f)
>> });
>>
>>
>>
>> On Sat, Dec 9, 2023 at 9:40 PM David Alayachew <davidalayachew at gmail.com> wrote:
>>> Apologies - java.util.HexFormat
>>>
>>> That's what I get for firing from the hip, then looking afterwards.
More information about the openjfx-dev
mailing list