diff --git a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/App.kt b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/App.kt index db0f1e9..af40dcc 100644 --- a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/App.kt +++ b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/App.kt @@ -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) } diff --git a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/grid.kt b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/grid.kt index 8a75304..e939d59 100644 --- a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/grid.kt +++ b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/grid.kt @@ -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,