feat: répondre au clavier (chiffres, Entrée, Backspace) sur desktop

This commit is contained in:
herel committed 2026-08-31 10:01:12 +02:00
1 parent 75033324b9
commit 94cac69e36
1 file changed
+28 -1
@@ -1,6 +1,7 @@
package com.livrets.ui package com.livrets.ui
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@@ -31,7 +32,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.backhandler.BackHandler 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.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.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
@@ -85,11 +91,32 @@ private fun PlayingContent(
progress: Float, progress: Float,
onQuitRequest: () -> Unit, onQuitRequest: () -> Unit,
) { ) {
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) { focusRequester.requestFocus() }
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.windowInsetsPadding(WindowInsets.safeDrawing) .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, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
Row( Row(