https://kotlinlang.org logo
k

Kazemihabib1996

03/04/2020, 5:58 PM
I'm playing with Clip and Draw components can someone explain me why this doesn't produce a rounded shape rectangle?
Container(width = 400.dp, height = 400.dp) {
Clip(shape = RoundedCornerShape(20.dp)) {
Draw { canvas, parentsize ->
val outer = Rect(10f, 10f, 100f, 100f)
canvas.drawRect(outer, paint)
}
}
}
z

Zach Klippenstein (he/him) [MOD]

03/04/2020, 6:10 PM
I’m guessing it’s because
Clip
uses its parent’s bounds, not its child: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1581336136434700?thread_ts=1581040037.376000&cid=CJLTWPH7S
👍 1
k

Kazemihabib1996

03/04/2020, 6:38 PM
Yes, you are right
Copy code
Surface(color = Color.Blue) {
        Container(width = 200.dp, height = 200.dp) {
            Clip(shape = RoundedCornerShape(10.dp)) {
                Draw { canvas, parentsize ->
            val outer = Rect.fromCircle(Offset(200f, 200f), radius = 100f)
                    canvas.drawRect(outer, paint)
                }
            }
        }
    }
produces the below image
but if I change the radius or Container size some interesting thing happens the below images:
2 Views