add additonal snippets
parent
8ef054baa4
commit
ac412385bb
|
|
@ -7,4 +7,5 @@
|
||||||
start-page="docthor.md">
|
start-page="docthor.md">
|
||||||
|
|
||||||
<toc-element topic="docthor.md"/>
|
<toc-element topic="docthor.md"/>
|
||||||
|
<toc-element topic="Snippets.md"/>
|
||||||
</instance-profile>
|
</instance-profile>
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
# 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)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
@ -17,7 +17,9 @@ import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ImageBitmap
|
import androidx.compose.ui.graphics.ImageBitmap
|
||||||
import androidx.compose.ui.graphics.RectangleShape
|
import androidx.compose.ui.graphics.RectangleShape
|
||||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
|
import androidx.compose.ui.graphics.drawscope.rotate
|
||||||
import androidx.compose.ui.graphics.drawscope.scale
|
import androidx.compose.ui.graphics.drawscope.scale
|
||||||
|
import androidx.compose.ui.graphics.drawscope.withTransform
|
||||||
import androidx.compose.ui.graphics.graphicsLayer
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.graphics.painter.BitmapPainter
|
import androidx.compose.ui.graphics.painter.BitmapPainter
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
|
|
@ -32,6 +34,7 @@ import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.WindowPlacement
|
import androidx.compose.ui.window.WindowPlacement
|
||||||
import androidx.compose.ui.window.WindowPosition
|
import androidx.compose.ui.window.WindowPosition
|
||||||
import androidx.compose.ui.window.rememberWindowState
|
import androidx.compose.ui.window.rememberWindowState
|
||||||
|
import androidx.compose.ui.zIndex
|
||||||
import com.github.panpf.zoomimage.ZoomImage
|
import com.github.panpf.zoomimage.ZoomImage
|
||||||
import com.github.panpf.zoomimage.compose.ZoomState
|
import com.github.panpf.zoomimage.compose.ZoomState
|
||||||
import com.github.panpf.zoomimage.compose.rememberZoomState
|
import com.github.panpf.zoomimage.compose.rememberZoomState
|
||||||
|
|
@ -57,7 +60,6 @@ fun main() = auroraApplication {
|
||||||
position = WindowPosition.Aligned(Alignment.Center),
|
position = WindowPosition.Aligned(Alignment.Center),
|
||||||
size = DpSize(1000. dp, 800.dp)
|
size = DpSize(1000. dp, 800.dp)
|
||||||
)
|
)
|
||||||
|
|
||||||
AuroraWindow(
|
AuroraWindow(
|
||||||
skin = marinerSkin(),
|
skin = marinerSkin(),
|
||||||
title = "Document Viewer",
|
title = "Document Viewer",
|
||||||
|
|
@ -71,7 +73,6 @@ fun main() = auroraApplication {
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview
|
|
||||||
fun viewImage() {
|
fun viewImage() {
|
||||||
Column (
|
Column (
|
||||||
modifier = Modifier.fillMaxSize().auroraBackground()
|
modifier = Modifier.fillMaxSize().auroraBackground()
|
||||||
|
|
@ -163,16 +164,16 @@ data class PointConverter(
|
||||||
@Composable
|
@Composable
|
||||||
fun shapes(zoomableState: ZoomableState) {
|
fun shapes(zoomableState: ZoomableState) {
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
val scale = zoomableState.transform.scaleX
|
val scaleX = zoomableState.transform.scaleX
|
||||||
|
val scaleY = zoomableState.transform.scaleY
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.offset { IntOffset(
|
.offset { IntOffset(
|
||||||
((zoomableState.transform.offset.x + (288 * scale)) ).toInt(),
|
((zoomableState.transform.offset.x + (288 * scaleX)) ).toInt(),
|
||||||
((zoomableState.transform.offset.y + (697 * scale)) ).toInt()
|
((zoomableState.transform.offset.y + (697 * scaleY)) ).toInt()
|
||||||
) }
|
) }
|
||||||
.scale(zoomableState.transform.scaleX)
|
|
||||||
.clip(RectangleShape)
|
.clip(RectangleShape)
|
||||||
.size(100.dp)
|
.size(100.dp * scaleX)
|
||||||
.background(Color.Red)
|
.background(Color.Red)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -210,6 +211,8 @@ fun canvas(zoomableState: ZoomableState) {
|
||||||
// 288,
|
// 288,
|
||||||
// 741
|
// 741
|
||||||
// ],
|
// ],
|
||||||
|
|
||||||
|
|
||||||
drawRect(
|
drawRect(
|
||||||
Color.Blue,
|
Color.Blue,
|
||||||
topLeft = zoomableState.transform.offset + (Offset(288 * zoomableState.transform.scaleX,697 * zoomableState.transform.scaleY)),
|
topLeft = zoomableState.transform.offset + (Offset(288 * zoomableState.transform.scaleX,697 * zoomableState.transform.scaleY)),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue