Function

PolygonShape

Creates a PolygonShape whose geometry is defined by builder at layout resolution time.

CustomPolygonShapeSample

@Sampled
@Composable
fun CustomPolygonShapeSample() {
    // A diamond built from pixel coordinates derived from the resolved layout size, with an
    // exact 8dp corner rounding.
    val diamond = remember {
        PolygonShape {
            polygon(
                vertices =
                    listOf(
                        Offset(size.width / 2f, 0f),
                        Offset(size.width, size.height / 2f),
                        Offset(size.width / 2f, size.height),
                        Offset(0f, size.height / 2f),
                    ),
                rounding = CornerRounding(radius = 8.dp),
            )
        }
    }
    Box(Modifier.size(96.dp).clip(diamond).background(Color(0xFFFF5722)))
}

UnitSpacePolygonShapeSample

@Sampled
@Composable
fun UnitSpacePolygonShapeSample() {
    // A kite authored in the unit square [0..1] with per-vertex rounding in the same coordinate
    // space. The shape scales and centers into any container preserving its aspect ratio.
    val kite = remember {
        PolygonShape(
            PolygonShapeGeometry(
                vertices =
                    listOf(Offset(0.5f, 0f), Offset(1f, 0.4f), Offset(0.5f, 1f), Offset(0f, 0.4f)),
                perVertexRounding =
                    listOf(
                        CornerRounding(0.1f),
                        CornerRounding(0.15f),
                        CornerRounding(0.05f),
                        CornerRounding(0.15f),
                    ),
            )
        )
    }

    Box(Modifier.size(width = 120.dp, height = 84.dp).clip(kite).background(Color(0xFF673AB7)))
}

Content updated: