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

Added hex color conversion #1432

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

jsheely
Copy link
Contributor

@jsheely jsheely commented Jan 15, 2024

Solves issue #1354

I'm not sure if this is desired but seemed like an easy quality of life feature to allow hex to rgb for creating colors.


Please upvote 👍 this pull request if you are interested in it.

Copy link
Contributor

@patriksvensson patriksvensson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The constructor only tests the happy path.
  • I think public static Color.FromHex(string hex) would be a more desirable approach here from an API perspective.
  • All errors will need to be resolved.

@nils-a
Copy link
Contributor

nils-a commented Jan 16, 2024

  • I think public static Color.FromHex(string hex) would be a more desirable approach here from an API perspective.

I'd vote for a combination of public static Color ParseHex(string hex) and public static bool TryParseHex(string hex, out Color color)

@patriksvensson
Copy link
Contributor

We use "ToHex" so "FromHex" and "TryFromHex" is more consistent API wise

@FrankRay78
Copy link
Contributor

It looks like hex[2..4] is not supported in netstandard 2.0

@FrankRay78
Copy link
Contributor

Unfortunately, the build still breaks @jsheely - see the build log above, looks like simple char/string conversion error. Want to update and push again?

@FrankRay78
Copy link
Contributor

Thank you @jsheely, if no one else gets to it first, I'll review (and hopefully merge) your PR this week.

@FrankRay78 FrankRay78 added this to the 0.49 milestone Mar 20, 2024
@FrankRay78
Copy link
Contributor

Dear @patriksvensson, I have rebased this branch, implemented full unit test coverage for both happy and unhappy paths, and ensured the failure to parse an invalid colour raises a FormatException with (what seems to me) to be a reasonable message.

I think it's suitable for merging, please re-review when you can.

@github-actions github-actions bot added the ⭐ top pull request Top pull request. label Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ top pull request Top pull request.
Projects
Status: PR 📬
Development

Successfully merging this pull request may close these issues.

Ability to instantiate a new instance of the Color class with a HEX color as well as RGB.
4 participants