Skip to content

Instantly share code, notes, and snippets.

@riggaroo
Created March 21, 2019 15:26
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 riggaroo/ed6f70cc6289127bc4066dce024e86df to your computer and use it in GitHub Desktop.
Save riggaroo/ed6f70cc6289127bc4066dce024e86df to your computer and use it in GitHub Desktop.
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