{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

CacheDrawScope

public final class CacheDrawScope implements Density


Handle to a drawing environment that enables caching of content based on the resolved size. Consumers define parameters and refer to them in the captured draw callback provided in onDrawBehind or onDrawWithContent.

onDrawBehind will draw behind the layout's drawing contents however, onDrawWithContent will provide the ability to draw before or after the layout's contents

Summary

Public methods

float

The logical density of the display.

float

Current user preference for the scaling factor for fonts.

final @NonNull LayoutDirection

Provides the LayoutDirection.

final @NonNull Size

Provides the dimensions of the current drawing environment

final @NonNull DrawResult

Issue drawing commands to be executed before the layout content is drawn

final @NonNull DrawResult

Issue drawing commands before or after the layout's drawing contents

Inherited methods

From androidx.compose.ui.unit.Density
int

Convert Dp to Int by rounding

int

Convert Sp to Int by rounding

@NonNull Dp

Convert Sp to Dp.

@NonNull Dp
orgKt.toDp(int receiver)

Convert an Int pixel value to Dp.

@NonNull Dp
orgKt.toDp(float receiver)

Convert a Float pixel value to a Dp

@NonNull DpSize

Convert a Size to a DpSize.

float
orgKt.toPx(@NonNull Dp receiver)

Convert Dp to pixels.

float

Convert Sp to pixels.

@NonNull Rect

Convert a DpRect to a Rect.

@NonNull Size

Convert a DpSize to a Size.

@NonNull TextUnit
orgKt.toSp(@NonNull Dp receiver)

Convert Dp to Sp.

@NonNull TextUnit
orgKt.toSp(int receiver)

Convert an Int pixel value to Sp.

@NonNull TextUnit
orgKt.toSp(float receiver)

Convert a Float pixel value to a Sp

Public methods

getDensity

public float getDensity()

The logical density of the display. This is a scaling factor for the Dp unit.

getFontScale

public float getFontScale()

Current user preference for the scaling factor for fonts.

getLayoutDirection

public final @NonNull LayoutDirection getLayoutDirection()

Provides the LayoutDirection.

getSize

public final @NonNull Size getSize()

Provides the dimensions of the current drawing environment

onDrawBehind

public final @NonNull DrawResult onDrawBehind(
    @ExtensionFunctionType @NonNull Function1<@NonNull DrawScopeUnit> block
)

Issue drawing commands to be executed before the layout content is drawn

onDrawWithContent

public final @NonNull DrawResult onDrawWithContent(
    @ExtensionFunctionType @NonNull Function1<@NonNull ContentDrawScopeUnit> block
)

Issue drawing commands before or after the layout's drawing contents