0

Please see the design enter image description here

This is what I troubleshoot, but it is not giving the expected output

Code:

@Composable
fun DrawBrackets() {
    Box(
        modifier = Modifier
            .height(200.dp)
            .width(200.dp)
    ) {

    Canvas(
        modifier = Modifier
            .height(200.dp)
            .width(200.dp)
    ) {
        val width = size.width
        val height = size.height
        val halfWidth = width.times(.5f)
        val halfHeight = height.times(.5f)

        val startPoints = listOf(
            PointF(0f, height),
            PointF(width, height),
        )

        val path = Path().apply {
            startPoints.forEach { point ->

                val curveXPart1 =
                    if (point.x > halfWidth)
                        width.minus(halfWidth.times(.5f))
                    else
                        halfWidth.times(.5f)

                val curveXPart2 =
                    if (point.x > halfWidth)
                        width.minus(halfWidth.times(.7f))
                    else
                        halfWidth.times(.7f)

                val curve1 = PointF(curveXPart1, point.y)
                val curve2 = PointF(curveXPart1, halfHeight - ((halfHeight - point.y) / 2))

                moveTo(point.x, point.y)
                quadraticBezierTo(
                    curve1.x,
                    curve1.y,
                    curve2.x,
                    curve2.y,
                )
                quadraticBezierTo(
                    curveXPart1,
                    halfHeight,
                    curveXPart2,
                    halfHeight,
                )
            }
        }
        drawPath(
            path = path,
            color = Color.Black,
            style = Stroke(width = 20f, cap = StrokeCap.Round)
        )
    }
    }
}

Please help. I don't also know what view I can try it out. I searched few questions on StackOverflow but not getting expected output. Please help. I don't also know what view I can try it out. I searched few questions on StackOverflow but not getting expected output.

0 Answers0