V.Rashkov
V.Rashkov

Reputation: 1735

How to round only bottom 2 corners with drawRoundRect in Jetpack Compose Canvas

As the title says, I am just trying to figure out how can I round only the bottom 2 corners of the round rect.

drawScope.drawRoundRect(
                topLeft = Offset(0f,0f),
                size = Size(100f,100f),
                cornerRadius = CornerRadius(x = 10f, y = 10f),
                color = boxPaint.color
            )

This is my current code, which rounds all corners.

Upvotes: 12

Views: 8782

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 88142

Seems like with drawRoundRect you only can setup left or right corner radius.

When you find that the Canvas API is missing something, you can draw almost anything using Path - it has much more flexible API.

val cornerRadius = CornerRadius(10f, 10f)
val path = Path().apply {
    addRoundRect(
        RoundRect(
            rect = Rect(
                offset = Offset(0f, 0f),
                size = Size(100f, 100f),
            ),
            bottomLeft = cornerRadius,
            bottomRight = cornerRadius,
        )
    )
}
drawPath(path, color = Color.Red)

Upvotes: 23

Related Questions