Interface

PolygonShapeScope

Builds PolygonShapeGeometry for a PolygonShape at layout resolution.

PolygonShapeSample

@Sampled
@Composable
fun PolygonShapeSample() {
    // A regular hexagon sized to the container's smaller dimension with an exact 16.dp corner
    // rounding resolved against the current density.
    val hexagon = remember {
        PolygonShape {
            polygon(
                numVertices = 6,
                radius = size.minDimension / 2f,
                center = Offset(size.width / 2f, size.height / 2f),
                rounding = CornerRounding.dp(radius = 16.dp),
            )
        }
    }
    Box(Modifier.size(96.dp).clip(hexagon).background(Color(0xFF3F51B5)))
}

DirectionalPolygonShapeSample

@Sampled
@Composable
fun DirectionalPolygonShapeSample() {
    // A pointed tag whose arrow tip adapts to the layout size and flips horizontally in RTL.
    val tag = remember {
        PolygonShape {
            val isLtr = layoutDirection == LayoutDirection.Ltr
            val tipX = if (isLtr) size.width else 0f
            val baseX = if (isLtr) 0f else size.width
            val indentX = if (isLtr) size.width * 0.2f else size.width * 0.8f
            polygon(
                vertices =
                    listOf(
                        Offset(baseX, 0f),
                        Offset(tipX, size.height / 2f),
                        Offset(baseX, size.height),
                        Offset(indentX, size.height / 2f),
                    ),
                rounding = CornerRounding.dp(radius = 6.dp),
            )
        }
    }
    Box(Modifier.size(width = 120.dp, height = 64.dp).clip(tag).background(Color(0xFF4CAF50)))
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: