# ProtoLayoutScope

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/ProtoLayoutScope.kt+class:androidx.wear.protolayout.ProtoLayoutScope) Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

*** ** * ** ***


```
@MainThread
public final class ProtoLayoutScope
```

<br />

*** ** * ** ***

A scope object responsible for handling internal details of ProtoLayout layouts and Tiles.

Object of this class, in Tiles cases, can be obtained via `androidx.wear.tiles.RequestBuilders#TileRequest.getScope` and shouldn't be created manually as it could lead to wrong tile behaviour, such as not correctly rendering resources.

Some example of usage:

- Used for registering Android resources automatically instead of manually via `androidx.wear.tiles.TileService.onTileResourcesRequest`.

This class is not thread safe and should only be used from one thread, `https://developer.android.com/reference/androidx/annotation/MainThread`.

## Summary

| ### Nested types |
|---|
| `public enum https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope.RendererCapability extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope.RendererCapability>` Defines the capabilities or features that a renderer can support. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope#ProtoLayoutScope(androidx.wear.protolayout.expression.VersionBuilders.VersionInfo)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/expression/VersionBuilders.VersionInfo rendererVersionInfo )` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope#collectPendingIntents()()` Returns a `https://developer.android.com/reference/android/os/Bundle.html` with all previously registered `https://developer.android.com/reference/android/app/PendingIntent.html`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.Resources` | `https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope#collectResources()()` Returns `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.Resources` object containing all previously registered resources, with {@link Image#setImageResource} and {@link Image#Builder(ProtoLayoutScope). |
| `final boolean` | `https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope#hasCapability(androidx.wear.protolayout.ProtoLayoutScope.RendererCapability)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope.RendererCapability capability)` Checks if the current tile renderer supports a specific capability. |
| `final boolean` | `https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope#hasResources()()` Returns whether this scope has any registered `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.Resources` or not. |

| ### Extension functions |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable` | `https://developer.android.com/reference/androidx/wear/protolayout/ClickableKt.https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope#(androidx.wear.protolayout.ProtoLayoutScope).clickable(android.app.PendingIntent,kotlin.String,androidx.wear.protolayout.ActionBuilders.Action,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/PendingIntent.html pendingIntent, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html id, https://developer.android.com/reference/androidx/wear/protolayout/ActionBuilders.Action fallbackAction, @https://developer.android.com/reference/androidx/annotation/Dimension(unit = 0) float minClickableWidth, @https://developer.android.com/reference/androidx/annotation/Dimension(unit = 0) float minClickableHeight )` Creates a `https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable` that allows the modified element to have a `https://developer.android.com/reference/android/app/PendingIntent.html` associated with it, which will be sent when the element is tapped. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Image` | `https://developer.android.com/reference/androidx/wear/protolayout/ImageKt.https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope#(androidx.wear.protolayout.ProtoLayoutScope).basicImage(androidx.wear.protolayout.ResourceBuilders.ImageResource,androidx.wear.protolayout.DimensionBuilders.ImageDimension,androidx.wear.protolayout.DimensionBuilders.ImageDimension,kotlin.String,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.ImageResource resource, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ImageDimension width, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ImageDimension height, https://developer.android.com/reference/java/lang/String.html protoLayoutResourceId, https://developer.android.com/reference/androidx/wear/protolayout/modifiers/LayoutModifier modifier, int contentScaleMode, https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutColor tintColor )` Builds an image from the given resources. |

## Public constructors

### ProtoLayoutScope

Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
public ProtoLayoutScope(
    @NonNull VersionBuilders.VersionInfo rendererVersionInfo
)
```

## Public methods

### collectPendingIntents

Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
public final @NonNull Bundle collectPendingIntents()
```

Returns a `https://developer.android.com/reference/android/os/Bundle.html` with all previously registered `https://developer.android.com/reference/android/app/PendingIntent.html`.

Bundle contains (key, value) pairs of `https://developer.android.com/reference/android/os/Parcelable.html`, where `key` is String ID corresponding to the `https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable` ID, and `value` is `https://developer.android.com/reference/android/app/PendingIntent.html`.

PendingIntent is registered when building a `https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable` which sets a `https://developer.android.com/reference/android/app/PendingIntent.html` as its click response.

### collectResources

Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
public final @NonNull ResourceBuilders.Resources collectResources()
```

Returns `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.Resources` object containing all previously registered resources, with {@link Image#setImageResource} and {@link Image#Builder(ProtoLayoutScope).

Resource is registered with the String ID that is a hash value of all resources.

### hasCapability

Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
public final boolean hasCapability(@NonNull ProtoLayoutScope.RendererCapability capability)
```

Checks if the current tile renderer supports a specific capability.

### hasResources

Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
public final boolean hasResources()
```

Returns whether this scope has any registered `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.Resources` or not.

## Extension functions

### ClickableKt.clickable

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/modifiers/Clickable.kt+function:clickable)

```
public final @NonNull ModifiersBuilders.Clickable ClickableKt.clickable(
    @NonNull ProtoLayoutScope receiver,
    @NonNull PendingIntent pendingIntent,
    @NonNull String id,
    ActionBuilders.Action fallbackAction,
    @Dimension(unit = 0) float minClickableWidth,
    @Dimension(unit = 0) float minClickableHeight
)
```

Creates a `https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable` that allows the modified element to have a `https://developer.android.com/reference/android/app/PendingIntent.html` associated with it, which will be sent when the element is tapped.

This clickable requires to be created in a `https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope` receiver scope which handles internal details of ProtoLayout layout and tiles. In Tiles cases, this scope object can be obtained via `androidx.wear.tiles.RequestBuilders#TileRequest.getScope`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/PendingIntent.html pendingIntent` | is sent when the element is tapped. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html id` | is the associated identifier for this clickable. This will be used to the identify the pendingIntent to send in the renderer. Within the same tile, this id must be unique among all pendingIntent clickables. |
| `https://developer.android.com/reference/androidx/wear/protolayout/ActionBuilders.Action fallbackAction` | The Action to use as a fallback when PendingIntent isn't supported by the ProtoLayout Renderer. |
| `@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 0) float minClickableWidth` | of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable width is not guaranteed unless there is enough space around the element within its parent bounds. |
| `@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 0) float minClickableHeight` | of the clickable area. The default value is 48dp, following the Material design accessibility guideline. Note that this value does not affect the layout, so the minimum clickable height is not guaranteed unless there is enough space around the element within its parent bounds. |

### ImageKt.basicImage

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/layout/Image.kt+function:basicImage)

```
public final @NonNull LayoutElementBuilders.Image ImageKt.basicImage(
    @NonNull ProtoLayoutScope receiver,
    @NonNull ResourceBuilders.ImageResource resource,
    @NonNull DimensionBuilders.ImageDimension width,
    @NonNull DimensionBuilders.ImageDimension height,
    String protoLayoutResourceId,
    LayoutModifier modifier,
    int contentScaleMode,
    LayoutColor tintColor
)
```

Builds an image from the given resources.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.ImageResource resource` | An Image resource, used in the layout in the place of this element |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ImageDimension width` | The width of the image |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ImageDimension height` | The height of the image |
| `https://developer.android.com/reference/java/lang/String.html protoLayoutResourceId` | The optional String ID for the resource. This is optional as it has a default value assigned by the automatic resource registration, but can be used to override it if desired to mark the resource with readable ID. |
| `https://developer.android.com/reference/androidx/wear/protolayout/modifiers/LayoutModifier modifier` | Modifiers to set to this element |
| `int contentScaleMode` | Defines how the content which does not match the dimensions of its bounds (e.g. an image resource being drawn inside an Image) will be resized to fit its bounds |
| `https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutColor tintColor` | The tint color to apply to the image |