public sealed class PolygonShape : Shape
Defines a Shape built from rounded polygon geometry.
Create instances with PolygonShape or companion factories like regularPolygon and star.
- Call
transformto rotate, translate, scale, apply aMatrix, or fit the geometry into the - Call copy before mutating a shared shape to keep the original unchanged.
layout bounds in place.
Note: Caches the resolved Outline for the most recent layout size, and shares returned Outline instances across callers. Do not mutate the Outline returned by createOutline.
Functions
transform
public fun transform(block: PolygonShapeTransformScope.() -> Unit)
Transforms this PolygonShape's geometry in place using block.
- Runs
blockin PolygonShapeTransformScope during outline resolution, deferring Compose - Replaces any transformation block previously set on this shape via
transform. - Mutates this PolygonShape in place; call copy first to keep a shared base shape
state reads out of composition so animated transforms update without recomposition.
unchanged.
Parameters
| block | transformation block run in PolygonShapeTransformScope at resolution time |
copy
public fun copy(): PolygonShape
Creates an independent copy of this PolygonShape and its transformations.
Subsequent in-place mutations via transform on the returned copy do not affect this shape, and vice versa.
Return
a new PolygonShape with the same base geometry and transformation configuration
Members
Companion
public companion object
Functions
regularPolygon
public fun regularPolygon(
@IntRange(from = 3) numVertices: Int,
rounding: CornerRounding = CornerRounding.Unrounded,
): PolygonShape
Creates a regular polygon PolygonShape inscribed in the container's smaller dimension.
Parameters
| numVertices | number of vertices, at least 3 |
| rounding | corner rounding resolved against the polygon's radius |
Throws: IllegalArgumentException
if numVertices is less than 3
star
public fun star(
@IntRange(from = 2) numPoints: Int,
innerRadiusRatio: Float = 0.5f,
outerRounding: CornerRounding = CornerRounding.Unrounded,
innerRounding: CornerRounding = outerRounding,
): PolygonShape
Creates a star PolygonShape inscribed in the container's smaller dimension.
Parameters
| numPoints | number of star tips, at least 2 |
| innerRadiusRatio | ratio of inner radius to outer radius, in (0f, 1f) |
| outerRounding | rounding for outer tips, resolved against the star's outer radius |
| innerRounding | rounding for inner corners, resolved against the star's outer radius |
Throws: IllegalArgumentException
if numPoints is less than 2 or innerRadiusRatio is outside (0f, 1f)
pill
public fun pill(@FloatRange(from = 0.0, to = 1.0) smoothing: Float = 0f): PolygonShape
Creates a pill PolygonShape with rounded ends along the shorter container sides.
Parameters
| smoothing | transition smoothness between the endcap arcs and straight edges, in 0f..1f (0f keeps a purely circular arc) |
Throws: IllegalArgumentException
if smoothing is outside 0f..1f
pillStar
public fun pillStar(
@IntRange(from = 2) numPoints: Int,
innerRadiusRatio: Float = 0.5f,
@FloatRange(from = 0.0, to = 1.0) vertexSpacing: Float = 0.5f,
@FloatRange(from = 0.0, to = 1.0) startLocation: Float = 0f,
outerRounding: CornerRounding = CornerRounding.Unrounded,
innerRounding: CornerRounding = outerRounding,
): PolygonShape
Creates a star PolygonShape with vertices distributed along a pill outline.
vertexSpacing controls how vertices are spaced around the curved ends:
0f: spaces inner vertices evenly along the curved ends1f: spaces outer vertices evenly along the curved ends0.5f(default): averages inner and outer spacing symmetrically
Parameters
| numPoints | number of star tips, at least 2 |
| innerRadiusRatio | ratio of inner radius to outer radius, in (0f, 1f) |
| vertexSpacing | curved-end vertex spacing policy, in 0f..1f |
| startLocation | perimeter offset where the outline starts, in 0f..1f |
| outerRounding | rounding for outer tips, resolved against the star's outer radius |
| innerRounding | rounding for inner corners, resolved against the star's outer radius |
Throws: IllegalArgumentException
if numPoints is less than 2, innerRadiusRatio is outside (0f, 1f), or vertexSpacing or startLocation is outside 0f..1f
circle
public fun circle(@IntRange(from = 3) numVertices: Int = 8): PolygonShape
Creates a circular PolygonShape approximated by numVertices rounded vertices.
Parameters
| numVertices | number of vertices approximating the circle, at least 3 |
Throws: IllegalArgumentException
if numVertices is less than 3
rectangle
public fun rectangle(rounding: CornerRounding): PolygonShape
Creates a rectangular PolygonShape filling the layout bounds with uniform rounding.
Parameters
| rounding | corner rounding for all 4 corners, resolved against the layout bounds |
rectangle
public fun rectangle(
topStartRounding: CornerRounding = CornerRounding.Unrounded,
topEndRounding: CornerRounding = CornerRounding.Unrounded,
bottomEndRounding: CornerRounding = CornerRounding.Unrounded,
bottomStartRounding: CornerRounding = CornerRounding.Unrounded,
): PolygonShape
Creates a rectangular PolygonShape with independent layout-direction-aware corners.
Corner roundings mirror automatically in LayoutDirection.Rtl.
Parameters
| topStartRounding | top-start corner rounding, resolved against the layout bounds |
| topEndRounding | top-end corner rounding, resolved against the layout bounds |
| bottomEndRounding | bottom-end corner rounding, resolved against the layout bounds |
| bottomStartRounding | bottom-start corner rounding, resolved against the layout bounds |
absoluteRectangle
public fun absoluteRectangle(
topLeftRounding: CornerRounding = CornerRounding.Unrounded,
topRightRounding: CornerRounding = CornerRounding.Unrounded,
bottomRightRounding: CornerRounding = CornerRounding.Unrounded,
bottomLeftRounding: CornerRounding = CornerRounding.Unrounded,
): PolygonShape
Creates a rectangular PolygonShape with fixed left/right corner roundings.
Corner roundings do not mirror with LayoutDirection.
Parameters
| topLeftRounding | top-left corner rounding, resolved against the layout bounds |
| topRightRounding | top-right corner rounding, resolved against the layout bounds |
| bottomRightRounding | bottom-right corner rounding, resolved against the layout bounds |
| bottomLeftRounding | bottom-left corner rounding, resolved against the layout bounds |