From afb891db83940f2bc09e6cf5cf59307964bc740c Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Thu, 15 Aug 2024 10:09:47 +0200 Subject: [PATCH] Standalone: Fix key repeat GitHub: #81 --- .../src/main/kotlin/gg/essential/example/main.kt | 10 ++++++++++ .../gg/essential/universal/standalone/UCWindow.kt | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/standalone/example/src/main/kotlin/gg/essential/example/main.kt b/standalone/example/src/main/kotlin/gg/essential/example/main.kt index 2c0d2e7..427e815 100644 --- a/standalone/example/src/main/kotlin/gg/essential/example/main.kt +++ b/standalone/example/src/main/kotlin/gg/essential/example/main.kt @@ -1,7 +1,9 @@ package gg.essential.example import gg.essential.elementa.components.UIRoundedRectangle +import gg.essential.elementa.components.input.UITextInput import gg.essential.elementa.dsl.constrain +import gg.essential.elementa.dsl.pixels import gg.essential.elementa.font.DefaultFonts import gg.essential.elementa.layoutdsl.* import gg.essential.elementa.state.v2.State @@ -81,6 +83,14 @@ fun LayoutScope.exampleScreen(extraFontsLoaded: State) { } row(Modifier.height(17f)) {} } + box(Modifier.childBasedSize(padding = 1f).color(Color.GRAY)) { + val textInput = UITextInput("Text Input") + textInput.setMinWidth(100.pixels) + textInput.setMaxWidth(100.pixels) + box(Modifier.childBasedSize(padding = 2f).color(Color.DARK_GRAY)) { + textInput() + }.onMouseClick { textInput.grabWindowFocus() } + } box(Modifier.childBasedSize(5f).color(Color.GRAY).hoverColor(Color.LIGHT_GRAY).hoverScope()) { geistText("Quit") }.onMouseClick { diff --git a/standalone/src/main/kotlin/gg/essential/universal/standalone/UCWindow.kt b/standalone/src/main/kotlin/gg/essential/universal/standalone/UCWindow.kt index f823b60..b9b37b4 100644 --- a/standalone/src/main/kotlin/gg/essential/universal/standalone/UCWindow.kt +++ b/standalone/src/main/kotlin/gg/essential/universal/standalone/UCWindow.kt @@ -72,7 +72,7 @@ class UCWindow(val glfwWindow: GlfwWindow, val uiScope: CoroutineScope) { GLFW.glfwSetKeyCallback(glfwWindow.glfwId) { _, key, _, action, modifiers -> uiScope.launch { when (action) { - GLFW.GLFW_PRESS -> { + GLFW.GLFW_PRESS, GLFW.GLFW_REPEAT -> { UKeyboard.keysDown.add(key) UScreen.currentScreen?.onKeyPressed(key, 0.toChar(), modifiers.toModifiers()) }