Add keyboard control (WIP, broken)
This commit is contained in:
@@ -62,10 +62,10 @@ fun App(
|
||||
PuzzleGrid(
|
||||
modifier = Modifier
|
||||
.focus(focusable),
|
||||
remember { focusable.createChild(Key.DirectionDown, Key.DirectionUp) },
|
||||
selectDirectly = selectDirectly,
|
||||
selectionManager = selectionManager,
|
||||
grid = game.grid,
|
||||
spacing = spacing,
|
||||
selectDirectly = selectDirectly,
|
||||
onUpdate = {
|
||||
horizontalClues.forEach { it.update(game.grid) }
|
||||
verticalClues.forEach { it.update(game.grid) }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ch.dissem.yaep.ui.common
|
||||
|
||||
import SelectionManager
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@@ -12,6 +13,7 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import ch.dissem.yaep.domain.GameCell
|
||||
@@ -19,11 +21,13 @@ import ch.dissem.yaep.domain.GameRow
|
||||
import ch.dissem.yaep.domain.Grid
|
||||
import ch.dissem.yaep.domain.Item
|
||||
import ch.dissem.yaep.domain.ItemClass
|
||||
import focus
|
||||
|
||||
@Composable
|
||||
fun PuzzleGrid(
|
||||
modifier: Modifier = Modifier,
|
||||
selectDirectly: Boolean,
|
||||
selectionManager: SelectionManager,
|
||||
spacing: Dp = 8.dp,
|
||||
grid: Grid,
|
||||
onUpdate: () -> Unit
|
||||
@@ -36,7 +40,8 @@ fun PuzzleGrid(
|
||||
onSnapshot = { grid.snapshot() },
|
||||
onUndo = { grid.undo() },
|
||||
spacing = spacing,
|
||||
selectDirectly = selectDirectly
|
||||
selectDirectly = selectDirectly,
|
||||
selectionManager = selectionManager
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -49,15 +54,20 @@ private fun PuzzleRow(
|
||||
onSnapshot: () -> Unit,
|
||||
onUndo: () -> Boolean,
|
||||
spacing: Dp,
|
||||
selectDirectly: Boolean
|
||||
selectDirectly: Boolean,
|
||||
selectionManager: SelectionManager
|
||||
) {
|
||||
val focusableRow = remember { selectionManager.add() }
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
) {
|
||||
val allOptions = row.options
|
||||
val columnSelectionManager =
|
||||
remember { focusableRow.createChild(Key.DirectionRight, Key.DirectionLeft) }
|
||||
for (cell in row) {
|
||||
val focusableItem = remember { columnSelectionManager.add() }
|
||||
var selection by remember(cell) { mutableStateOf(cell.selection) }
|
||||
val options = remember(cell) {
|
||||
allOptions.map { Toggleable(it, cell.options.contains(it)) }
|
||||
@@ -73,6 +83,7 @@ private fun PuzzleRow(
|
||||
}
|
||||
Selector(
|
||||
modifier = Modifier
|
||||
.focus(focusableItem)
|
||||
.padding(spacing)
|
||||
.weight(1f),
|
||||
spacing,
|
||||
|
||||
Reference in New Issue
Block a user