diff --git a/sharedUI/src/commonMain/kotlin/com/livrets/ui/GameScreen.kt b/sharedUI/src/commonMain/kotlin/com/livrets/ui/GameScreen.kt index 21d395d..1de899d 100644 --- a/sharedUI/src/commonMain/kotlin/com/livrets/ui/GameScreen.kt +++ b/sharedUI/src/commonMain/kotlin/com/livrets/ui/GameScreen.kt @@ -1,6 +1,7 @@ package com.livrets.ui import androidx.compose.foundation.background +import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -31,7 +32,12 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.backhandler.BackHandler +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color +import androidx.compose.ui.input.key.key +import androidx.compose.ui.input.key.onPreviewKeyEvent +import androidx.compose.ui.input.key.type import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -85,11 +91,32 @@ private fun PlayingContent( progress: Float, onQuitRequest: () -> Unit, ) { + val focusRequester = remember { FocusRequester() } + LaunchedEffect(Unit) { focusRequester.requestFocus() } Column( modifier = Modifier .fillMaxSize() .windowInsetsPadding(WindowInsets.safeDrawing) - .padding(24.dp), + .padding(24.dp) + .focusRequester(focusRequester) + .focusable() + .onPreviewKeyEvent { event -> + when (val action = GameKeyMapping.actionFor(event.key, event.type)) { + is KeypadAction.Digit -> { + engine.onDigit(action.char) + true + } + KeypadAction.Delete -> { + engine.onDelete() + true + } + KeypadAction.Validate -> { + engine.onValidate() + true + } + null -> false + } + }, horizontalAlignment = Alignment.CenterHorizontally, ) { Row(