Splitties
Splitties copied to clipboard
ColorInt extensions
Don't you think this would create overlap with AndroidX Core KTX component# functions used for destructuring?
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