Function

scaledToFit

Returns a new PolygonShape scaled and aligned into the layout bounds.

scaledToFit

Source set: Common
public fun PolygonShape.scaledToFit(
    contentScale: ContentScale = ContentScale.Fit,
    alignment: Alignment = Alignment.Center,
): PolygonShape

Returns a new PolygonShape 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 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

Content updated: