Created
March 21, 2019 15:26
-
-
Save riggaroo/ed6f70cc6289127bc4066dce024e86df to your computer and use it in GitHub Desktop.
Sample of Canvas extension function from Android KTX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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