Bounding Box

Author: Vinay Gaba

Use this Modifier to add a bounding box around the @Composable function that it's applied to. The most common use case for this is to debug the bounds of a @Composable function.

fun Modifier.boundingBox(
    color: Color = Color.Red,
    strokeWidth: Float = 5f,
) = drawWithCache {
    val stroke = Stroke(strokeWidth)
    val size = Size(size.width, size.height)
    onDrawWithContent {
        drawContent()
        drawRect(
            color = color,
            size = size,
            style = stroke
        )
    }
}

Have a project you'd like to submit? Fill this form, will ya!

If you like this snippet, you might also like:

Maker OS is an all-in-one productivity system for developers

I built Maker OS to track, manage & organize my life. Now you can do it too!