---
title: "scaledToFit"
description: "Returns a new [PolygonShape] scaled and aligned into the layout bounds."
type: "function"
lastmod: "2026-09-24"
---
## API Reference

### scaledToFit

> Source set: Common

```kotlin
public fun PolygonShape.scaledToFit(
    contentScale: ContentScale = ContentScale.Fit,
    alignment: Alignment = Alignment.Center,
): PolygonShape
```

Returns a new [PolygonShape](/jetpack-compose/androidx.compose.foundation/foundation/functions/PolygonShape/api) scaled and aligned into the layout bounds.

`contentScale` selects the scaling policy and `alignment` positions the scaled geometry:
- `ContentScale.Fit` (the default) scales uniformly to fit within bounds, preserving aspect ratio
- `ContentScale.FillBounds` stretches each axis independently to fill the bounds
- `ContentScale.Crop` fills the bounds, preserving aspect ratio and clipping overflow
- `ContentScale.None` applies no scaling

Measures the resolved geometry to place a shape accurately even when rounding pulls it inside its
nominal bounds. Predefined shapes and scope factories are already bounded; scaling is useful
after a [transformed](/jetpack-compose/androidx.compose.foundation/foundation/functions/transformed/api) call or when applying non-default placement policies.

Leaves the receiver untouched and derives a new shape value.

#### Parameters

| | |
| --- | --- |
| contentScale | how to scale the resolved geometry into the layout bounds |
| alignment | where to place the scaled geometry within the layout bounds |

## Code Examples

### ScaledToFitPolygonShapeSample

```kotlin
@Sampled
@Composable
fun ScaledToFitPolygonShapeSample() {
    // Inside a wide container the star keeps its aspect ratio and is centered; passing
    // ContentScale.FillBounds instead would stretch it to fill the container.
    val star = remember {
        PolygonShape.star(
                numPoints = 5,
                innerRadiusRatio = 0.5f,
                outerRounding = CornerRounding(percent = 30),
            )
            .scaledToFit(contentScale = ContentScale.Fit)
    }
    Box(Modifier.size(width = 160.dp, height = 64.dp).clip(star).background(Color(0xFF9C27B0)))
}
```
