docthor/Writerside/topics/Snippets.md

36 lines
1.0 KiB
Markdown

# Snippets
## Scale a Shape alongside ZoomImage
```kotlin
@Composable
fun shapes(zoomableState: ZoomableState) {
Box(modifier = Modifier.fillMaxSize()) {
val scaleX = zoomableState.transform.scaleX
val scaleY = zoomableState.transform.scaleY
Box(
modifier = Modifier
.offset { IntOffset(
((zoomableState.transform.offset.x + (288 * scaleX)) ).toInt(),
((zoomableState.transform.offset.y + (697 * scaleY)) ).toInt()
) }
.clip(RectangleShape)
.size(100.dp * scaleX)
.background(Color.Red)
)
}
}
```
### Scale a Canvas alongside Zoomimage
```kotlin
drawRect(
Color.Blue,
topLeft = zoomableState.transform.offset + (Offset(288 * zoomableState.transform.scaleX,697 * zoomableState.transform.scaleY)),
size = Size( (793 - 288)* zoomableState.transform.scaleX, (741 - 697) * zoomableState.transform.scaleY),
style = Stroke(width = 5f)
)
```