Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.5 kB
2
Indexable
Never
@Composable
fun SegCheckBox(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier
) {
    Box(
        modifier = modifier
            .size(defaultGrid.grid_6)
            .clickable { onCheckedChange(!checked) }
    ) {
        Canvas(
            modifier = Modifier
                .fillMaxSize()
        ) {
            val strokeWidth = defaultGrid.grid_0_25.toPx()
            val cornerRadius = defaultGrid.grid_1.toPx()

            drawRoundRect(
                color = SegColors.GrayWhite,
                size = Size(size.width, size.height),
                cornerRadius = CornerRadius(cornerRadius)
            )

            drawRoundRect(
                color = SegColors.Purple,
                size = Size(size.width, size.height),
                cornerRadius = CornerRadius(cornerRadius),
                style = Stroke(strokeWidth)
            )
            
            if (checked) {
                val innerRectSize = Size(size.width * 2 / 3, size.height * 2 / 3)
                val left = (size.width - innerRectSize.width) / 2
                val top = (size.height - innerRectSize.height) / 2
                drawRoundRect(
                    color = SegColors.Purple,
                    size = innerRectSize,
                    topLeft = Offset(left, top),
                    cornerRadius = CornerRadius(cornerRadius)
                )
            }
        }
    }
}
Leave a Comment