Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with Hex codes #148

Closed
mswift42 opened this issue Oct 20, 2019 · 6 comments · Fixed by #157
Closed

Working with Hex codes #148

mswift42 opened this issue Oct 20, 2019 · 6 comments · Fixed by #157

Comments

@mswift42
Copy link
Contributor

Are there any plans for adding support for hex format, specifically something like rgb::new(hex) ?

@Ogeon
Copy link
Owner

Ogeon commented Oct 20, 2019

Nothing concrete at the moment, apart from #144 being at the other end of the pipeline, but there's not really any particular reason against it. Do you have any specific input format/type in mind? Like a string or a u32? Does the component order matter?

Also, just so it's not forgotten, if it's just for being able to input it in hex instead of decimal, it can always be broken up into u8 components:

let color: Srgb<u8> = Srgb::new(0xFF, 0x00, 0xFF);

@mswift42
Copy link
Contributor Author

I need to parse hex color strings in format "#ff00dd" and convert that to rgb.

I can do the parsing / converting to rgb my self, I was just puzzled that working with hex colors wasn't more sought after.

@Ogeon
Copy link
Owner

Ogeon commented Oct 20, 2019

Sounds like a FromStr implementation for Srgb<u8> would fulfill that need. Or maybe a more specific from_hex method. 🙂

@mswift42
Copy link
Contributor Author

Yes, something like from_hex sounds great.

At the end of the day, hex is rgb, just written in a different notation.

The only problem is, you have to validate the input and "#fff" and "#ffffff" are the same thing.

@NickHu
Copy link

NickHu commented Mar 25, 2021

One issue is that you don't get an Eq instance for Srgb<u8>; should there be an impl for Rgb<S, T> when T: Eq? Does this hurt anything? I'm currently running in to this myself...

@Ogeon
Copy link
Owner

Ogeon commented Mar 25, 2021

Oh, you are completely right! That must have been forgotten somewhere along the way. I'll report a separate issue for it, since this one is closed, and also make it a task to go through the other types and add it in there too. Just in case. Thanks for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants