Skip to content

Instantly share code, notes, and snippets.

@colinrtwhite
Created March 8, 2022 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinrtwhite/f74086cf7c24bca98ad2bc3141d955e9 to your computer and use it in GitHub Desktop.
Save colinrtwhite/f74086cf7c24bca98ad2bc3141d955e9 to your computer and use it in GitHub Desktop.
A painter that wraps another painter to overwrite its color filter and/or alpha.
open class ForwardingPainter(
private val delegate: Painter,
private var alpha: Float = DefaultAlpha,
private var colorFilter: ColorFilter? = null,
) : Painter() {
override val intrinsicSize get() = delegate.intrinsicSize
override fun applyAlpha(alpha: Float): Boolean {
if (alpha == DefaultAlpha) {
this.alpha = alpha
}
return true
}
override fun applyColorFilter(colorFilter: ColorFilter?): Boolean {
if (colorFilter == null) {
this.colorFilter = colorFilter
}
return true
}
override fun DrawScope.onDraw() {
with(delegate) {
draw(size, alpha, colorFilter)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment