Skip to content

Instantly share code, notes, and snippets.

@Mercandj
Last active April 13, 2023 09:54
Show Gist options
  • Save Mercandj/5595ab5d9c71e8e9dda60e020710b9bd to your computer and use it in GitHub Desktop.
Save Mercandj/5595ab5d9c71e8e9dda60e020710b9bd to your computer and use it in GitHub Desktop.
private fun Constraints.findSize(): IntSize {
val matchWidth = when (aspectRatioReference) {
AspectRatioReference.PARENT_WIDTH -> true
AspectRatioReference.PARENT_HEIGHT -> false
AspectRatioReference.MIN_PARENT_WIDTH_PARENT_HEIGHT -> maxWidth < maxHeight
AspectRatioReference.MAX_PARENT_WIDTH_PARENT_HEIGHT -> maxWidth > maxHeight
}
return if (matchWidth) {
IntSize(maxWidth, (maxWidth * aspectRatioHeight / aspectRatioWidth).roundToInt())
} else {
IntSize((maxHeight * aspectRatioWidth / aspectRatioHeight).roundToInt(), maxHeight)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment