Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample of Canvas extension function from Android KTX
/**
* Wrap the specified [block] in calls to [Canvas.save]/[Canvas.translate]
* and [Canvas.restoreToCount].
*/
inline fun Canvas.withTranslation(
x: Float = 0.0f,
y: Float = 0.0f,
block: Canvas.() -> Unit
) {
val checkpoint = save()
translate(x, y)
try {
block()
} finally {
restoreToCount(checkpoint)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment