feat: Remove unused PatternInput.kt file
This commit removes the file as the Composable function was not used anywhere in the project.
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
package de.lxtools.noteshop.ui
|
||||
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.gestures.detectDragGestures
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun PatternInput(
|
||||
onPatternComplete: (List<Int>) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var pattern by remember { mutableStateOf(emptyList<Int>()) }
|
||||
var currentPosition by remember { mutableStateOf<Offset?>(null) }
|
||||
val dotPositions = remember { mutableMapOf<Int, Offset>() }
|
||||
val density = LocalDensity.current
|
||||
|
||||
Box(modifier = modifier) {
|
||||
Canvas(modifier = Modifier
|
||||
.size(300.dp)
|
||||
.pointerInput(Unit) {
|
||||
detectDragGestures(
|
||||
onDragStart = { offset ->
|
||||
currentPosition = offset
|
||||
val dot = getDotAt(offset, dotPositions, density)
|
||||
if (dot != null && !pattern.contains(dot)) {
|
||||
pattern = pattern + dot
|
||||
}
|
||||
},
|
||||
onDrag = { change, _ ->
|
||||
currentPosition = change.position
|
||||
val dot = getDotAt(change.position, dotPositions, density)
|
||||
if (dot != null && !pattern.contains(dot)) {
|
||||
pattern = pattern + dot
|
||||
}
|
||||
},
|
||||
onDragEnd = {
|
||||
onPatternComplete(pattern)
|
||||
pattern = emptyList()
|
||||
currentPosition = null
|
||||
}
|
||||
)
|
||||
}) {
|
||||
val dotRadius = 16.dp.toPx()
|
||||
val dotColor = Color.Gray
|
||||
val selectedDotColor = Color.Black
|
||||
val lineColor = Color.Black
|
||||
|
||||
for (i in 1..9) {
|
||||
val row = (i - 1) / 3
|
||||
val col = (i - 1) % 3
|
||||
val x = col * (size.width / 3) + (size.width / 6)
|
||||
val y = row * (size.height / 3) + (size.height / 6)
|
||||
val center = Offset(x, y)
|
||||
dotPositions[i] = center
|
||||
drawCircle(
|
||||
color = if (pattern.contains(i)) selectedDotColor else dotColor,
|
||||
radius = dotRadius,
|
||||
center = center
|
||||
)
|
||||
}
|
||||
|
||||
if (pattern.isNotEmpty()) {
|
||||
for (i in 0 until pattern.size - 1) {
|
||||
val start = dotPositions[pattern[i]]
|
||||
val end = dotPositions[pattern[i + 1]]
|
||||
if (start != null && end != null) {
|
||||
drawLine(
|
||||
color = lineColor,
|
||||
start = start,
|
||||
end = end,
|
||||
strokeWidth = 8.dp.toPx()
|
||||
)
|
||||
}
|
||||
}
|
||||
val lastDot = pattern.last()
|
||||
val lastDotCenter = dotPositions[lastDot]
|
||||
if (lastDotCenter != null && currentPosition != null) {
|
||||
drawLine(
|
||||
color = lineColor,
|
||||
start = lastDotCenter,
|
||||
end = currentPosition!!,
|
||||
strokeWidth = 8.dp.toPx()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDotAt(offset: Offset, dotPositions: Map<Int, Offset>, density: Density): Int? {
|
||||
for ((dot, position) in dotPositions) {
|
||||
val distance = (offset - position).getDistance()
|
||||
if (distance < with(density) { 50.dp.toPx() }) {
|
||||
return dot
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user