# 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
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/kotlin/androidx/annotation/MainThread`.

## Summary

| ### Nested types |
|---|
| `enum https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope.RendererCapability : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope.RendererCapability>` Defines the capabilities or features that a renderer can support. |

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

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/kotlin/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`. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ResourceBuilders.Resources` | `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope#collectResources()()` Returns `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ResourceBuilders.Resources` object containing all previously registered resources, with {@link Image#setImageResource} and {@link Image#Builder(ProtoLayoutScope). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope#hasCapability(androidx.wear.protolayout.ProtoLayoutScope.RendererCapability)(capability: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope.RendererCapability)` Checks if the current tile renderer supports a specific capability. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope#hasResources()()` Returns whether this scope has any registered `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ResourceBuilders.Resources` or not. |

| ### Extension functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ModifiersBuilders.Clickable` | `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope.https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope#(androidx.wear.protolayout.ProtoLayoutScope).clickable(android.app.PendingIntent,kotlin.String,androidx.wear.protolayout.ActionBuilders.Action,kotlin.Float,kotlin.Float)( pendingIntent: https://developer.android.com/reference/android/app/PendingIntent.html, id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, fallbackAction: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ActionBuilders.Action?, minClickableWidth: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, minClickableHeight: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Creates a `https://developer.android.com/reference/kotlin/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. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.Image` | `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ProtoLayoutScope.https://developer.android.com/reference/kotlin/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)( resource: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ResourceBuilders.ImageResource, width: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.ImageDimension, height: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.ImageDimension, protoLayoutResourceId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, modifier: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/modifiers/LayoutModifier?, contentScaleMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, tintColor: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/types/LayoutColor? )` 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)

```
ProtoLayoutScope(
    rendererVersionInfo: VersionBuilders.VersionInfo = DEFAULT_RENDERER_VERSION
)
```

## Public functions

### collectPendingIntents

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

```
fun collectPendingIntents(): Bundle
```

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/kotlin/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/kotlin/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)

```
fun collectResources(): ResourceBuilders.Resources
```

Returns `https://developer.android.com/reference/kotlin/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)

```
fun hasCapability(capability: ProtoLayoutScope.RendererCapability): Boolean
```

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)

```
fun hasResources(): Boolean
```

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

## Extension functions

### ProtoLayoutScope.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)

```
fun ProtoLayoutScope.clickable(
    pendingIntent: PendingIntent,
    id: String,
    fallbackAction: ActionBuilders.Action? = null,
    minClickableWidth: @Dimension(unit = 0) Float = Float.NaN,
    minClickableHeight: @Dimension(unit = 0) Float = Float.NaN
): ModifiersBuilders.Clickable
```

Creates a `https://developer.android.com/reference/kotlin/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/kotlin/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 |
|---|---|
| `pendingIntent: https://developer.android.com/reference/android/app/PendingIntent.html` | is sent when the element is tapped. |
| `id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | 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. |
| `fallbackAction: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ActionBuilders.Action? = null` | The Action to use as a fallback when PendingIntent isn't supported by the ProtoLayout Renderer. |
| `minClickableWidth: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = Float.NaN` | 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. |
| `minClickableHeight: @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = Float.NaN` | 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. |

### ProtoLayoutScope.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)

```
fun ProtoLayoutScope.basicImage(
    resource: ResourceBuilders.ImageResource,
    width: DimensionBuilders.ImageDimension,
    height: DimensionBuilders.ImageDimension,
    protoLayoutResourceId: String? = null,
    modifier: LayoutModifier? = null,
    contentScaleMode: Int = CONTENT_SCALE_MODE_UNDEFINED,
    tintColor: LayoutColor? = null
): LayoutElementBuilders.Image
```

Builds an image from the given resources.

| Parameters |
|---|---|
| `resource: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ResourceBuilders.ImageResource` | An Image resource, used in the layout in the place of this element |
| `width: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.ImageDimension` | The width of the image |
| `height: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.ImageDimension` | The height of the image |
| `protoLayoutResourceId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | 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. |
| `modifier: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/modifiers/LayoutModifier? = null` | Modifiers to set to this element |
| `contentScaleMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = CONTENT_SCALE_MODE_UNDEFINED` | 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 |
| `tintColor: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/types/LayoutColor? = null` | The tint color to apply to the image |