Drag gesture

This commit is contained in:
Alexey 2025-07-25 16:25:32 +03:00
commit 6fa590ff0a

View file

@ -7,6 +7,10 @@ import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.gestures.draggable
import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
@ -26,6 +30,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.tooling.preview.Preview
import com.mirenkov.ktheightmap.ui.theme.KtHeightMapTheme
@ -66,9 +71,11 @@ fun MapCanvas(
val offsetY = rememberSaveable { mutableFloatStateOf(0F) }
Canvas(
modifier = modifier.fillMaxSize()
.clickable {
offsetX.floatValue += 20
offsetY.floatValue += 20
.pointerInput(Unit) {
detectDragGestures { _, distance ->
offsetX.floatValue += distance.x
offsetY.floatValue += distance.y
}
}
) {
drawRect(