[SOLVED] Can someone tell me why the rectangle dra...
# compose
l
[SOLVED] Can someone tell me why the rectangle draw starts always at position 0, 0 no matter what value
left
and
top
is:
Copy code
fun Modifier.shadow(
    size: DpSize,
    color: Color = DefaultShadowColor,
    offsetX: Dp = 0.dp,
    offsetY: Dp = 0.dp,
    blurRadius: Dp = 0.dp,
) = then(
    drawBehind {
        drawIntoCanvas { canvas ->
            val paint = Paint()
            val frameworkPaint = paint.asFrameworkPaint()
            if (blurRadius != 0.dp) {
                frameworkPaint.maskFilter =
                    BlurMaskFilter(blurRadius.toPx(), BlurMaskFilter.Blur.NORMAL)
            }
            frameworkPaint.color = color.toArgb()

            val leftPixel = offsetX.toPx()
            val topPixel = offsetY.toPx()
            val rightPixel = size.width.toPx()
            val bottomPixel = size.height.toPx()

            canvas.drawRect(
                left = leftPixel,
                top = topPixel,
                right = rightPixel,
                bottom = bottomPixel,
                paint = paint,
            )
        }
    }
)
r
Note that
rightPixel
should be
leftPixel + size.width.toPx()
in your case. Same for
bottomPixel
👍 1
l
Thanks boss :)