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

ColorInt extensions #174

Open
Ribesg opened this issue Feb 27, 2019 · 2 comments
Open

ColorInt extensions #174

Ribesg opened this issue Feb 27, 2019 · 2 comments

Comments

@Ribesg
Copy link

Ribesg commented Feb 27, 2019

Would be nice to get some things similar to these and/or these :)

@LouisCAD
Copy link
Owner

Don't you think this would create overlap with AndroidX Core KTX component# functions used for destructuring?

@LouisCAD LouisCAD changed the title Color extensions ColorInt extensions Feb 27, 2019
@Ribesg
Copy link
Author

Ribesg commented Feb 27, 2019

Right, such extensions should really add value.
My only example right now is setting the alpha of a color int.

inline fun Int.alpha(alpha: Double): Int {
    require(alpha in 0.0..1.0)
    return ColorUtils.setAlphaComponent(this, (alpha * 0xFF).toInt())
}

ColorUtils and the Color class are overall pretty verbose, in some cases you can write pretty long code for nothing much. The above extension allows me to replace this:

ColorUtils.setAlphaComponent(color(R.color.red), (.25 * 0xFF).toInt())

with this:

color(R.color.red).alpha(.25)

Obviously KTX provides everything needed for getters, we have Int.alpha, etc

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

No branches or pull requests

2 participants