Class

PolygonShape

Defines a Shape built from rounded polygon geometry.

Source set: Common
public sealed class PolygonShape : Shape

Defines a Shape built from rounded polygon geometry.

Create instances with PolygonShape or companion factories like regularPolygon and star.

    layout bounds in place.

  • Call transform to rotate, translate, scale, apply a Matrix, or fit the geometry into the
  • Call copy before mutating a shared shape to keep the original unchanged.

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

Source set: Common
public fun transform(block: PolygonShapeTransformScope.() -> Unit)

Transforms this PolygonShape's geometry in place using block.

    state reads out of composition so animated transforms update without recomposition.

  • Runs block in PolygonShapeTransformScope during outline resolution, deferring Compose
  • Replaces any transformation block previously set on this shape via transform.
  • unchanged.

  • Mutates this PolygonShape in place; call copy first to keep a shared base shape

Parameters

block transformation block run in PolygonShapeTransformScope at resolution time

copy

Source set: Common
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

Source set: Common
public companion object

Functions

regularPolygon

Source set: Common
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

Source set: Common
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

Source set: Common
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

Source set: Common
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 ends
  • 1f: spaces outer vertices evenly along the curved ends
  • 0.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

Source set: Common
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

Source set: Common
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

Source set: Common
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

Source set: Common
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

Content updated: