Skip to content

Instantly share code, notes, and snippets.

@DUMA042
Created January 10, 2025 23:15
Show Gist options
  • Save DUMA042/5076a8919e4eb4210cdb5de2c8101ffd to your computer and use it in GitHub Desktop.
Save DUMA042/5076a8919e4eb4210cdb5de2c8101ffd to your computer and use it in GitHub Desktop.
@Composable
fun DrawRectangle(rect: Rect?) {
// Convert the Android Rect to a Compose Rect
val composeRect = rect?.toComposeRect()
// Draw the rectangle on a Canvas if the rect is not null
composeRect?.let {
Canvas(modifier = Modifier.fillMaxSize()) {
drawRect(
color = Color.Red,
topLeft = Offset(it.left, it.top), // Set the top-left position
size = Size(it.width, it.height), // Set the size of the rectangle
style = Stroke(width = 5f) // Use a stroke style with a width of 5f
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment