Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Supports macOS text input (missing full IME support) Some work on kor…
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jun 16, 2021
1 parent 0067124 commit 9fc673c
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 140 deletions.
Expand Up @@ -29,10 +29,13 @@ class UiFocusManager(override val view: Stage) : KeyComponent {

//private var toggleKeyboardTimeout: Closeable? = null

fun requestToggleSoftKeyboard(show: Boolean) {
fun requestToggleSoftKeyboard(show: Boolean, view: View?) {
//toggleKeyboardTimeout?.close()
//toggleKeyboardTimeout = stage.timeout(1.seconds) {
if (show) {
if (view != null) {
gameWindow.setInputRectangle(view.windowBounds)
}
gameWindow.showSoftKeyboard()
} else {
gameWindow.hideSoftKeyboard()
Expand Down
Expand Up @@ -200,13 +200,13 @@ class UiTextInput(initialText: String = "", width: Double = 128.0, height: Doubl
}
caret.visible = true
//println("stage?.gameWindow?.showSoftKeyboard(): ${stage?.gameWindow}")
stage?.uiFocusManager?.requestToggleSoftKeyboard(true)
stage?.uiFocusManager?.requestToggleSoftKeyboard(true, this)
} else {
if (stage?.uiFocusedView == this) {
stage?.uiFocusedView = null
caret.visible = false
if (stage?.uiFocusedView !is UiTextInput) {
stage?.uiFocusManager?.requestToggleSoftKeyboard(false)
stage?.uiFocusManager?.requestToggleSoftKeyboard(false, null)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt
Expand Up @@ -200,6 +200,9 @@ open class GameWindow : EventDispatcher.Mixin(), DialogInterface, Closeable, Cor

open val isSoftKeyboardVisible: Boolean get() = false

open fun setInputRectangle(windowRect: Rectangle) {
}

open fun showSoftKeyboard(force: Boolean = true) {
}

Expand Down Expand Up @@ -503,6 +506,7 @@ open class GameWindow : EventDispatcher.Mixin(), DialogInterface, Closeable, Cor

fun dispatchKeyEventEx(
type: KeyEvent.Type, id: Int, character: Char, key: Key, keyCode: Int,

shift: Boolean = this.shift, ctrl: Boolean = this.ctrl, alt: Boolean = this.alt, meta: Boolean = this.meta
) {
if (type != KeyEvent.Type.TYPE) {
Expand Down

0 comments on commit 9fc673c

Please sign in to comment.