From 94cac69e3607689cbb44d73355a8a433c4e89fa7 Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Mon, 31 Aug 2026 10:01:12 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20r=C3=A9pondre=20au=20clavier=20(chiffre?= =?UTF-8?q?s,=20Entr=C3=A9e,=20Backspace)=20sur=20desktop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/livrets/ui/GameScreen.kt | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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(