diff --git a/client/src/commonMain/kotlin/ui/custom/TextEditController.kt b/client/src/commonMain/kotlin/ui/custom/TextEditController.kt index 8c7b011..451861b 100644 --- a/client/src/commonMain/kotlin/ui/custom/TextEditController.kt +++ b/client/src/commonMain/kotlin/ui/custom/TextEditController.kt @@ -89,6 +89,7 @@ class TextEditController( private fun setTextNoSnapshot(text: String, out: TextSnapshot = TextSnapshot("", 0..0)): TextSnapshot? { if (!acceptTextChange(textView.text, text)) return null + println("'$text'") out.text = textView.text out.selectionRange = selectionRange textView.text = text @@ -121,14 +122,19 @@ class TextEditController( val lastStr = text[max(0, index - 1)] val insertion = khangul.HangulProcessor.composeHangul(lastStr + substr) if (insertion !== null) { - text = rangedText + val tempText = rangedText .withoutIndex(max(0, index - 1)) .withInsertion(index, insertion) - cursorIndex += insertion.length - 1 + text = tempText.makeStartWithSpace() + if (tempText.startsWith(" ")) { + cursorIndex += insertion.length - 1 + } else { + cursorIndex += insertion.length + } return } } - text = rangedText.withInsertion(index, substr) + text = rangedText.withInsertion(index, substr).makeStartWithSpace() cursorIndex += substr.length } @@ -406,7 +412,7 @@ class TextEditController( } if (it.key == Key.X) { val selection = selectionRange - text = text.withoutRange(selectionRange) + text = text.withoutRange(selectionRange).makeStartWithSpace() moveToIndex(false, selection.first) } } @@ -424,18 +430,23 @@ class TextEditController( Key.BACKSPACE, Key.DELETE -> { val range = selectionRange if (range.length > 0) { - text = text.withoutRange(range) + text = text.withoutRange(range).makeStartWithSpace() cursorIndex = range.first } else { if (it.key == Key.BACKSPACE) { if (cursorIndex > 0) { val oldCursorIndex = cursorIndex - text = text.withoutIndex(cursorIndex - 1) - cursorIndex = oldCursorIndex - 1 // This [oldCursorIndex] is required since changing text might change the cursorIndex already in some circumstances + var tempText = text.withoutIndex(cursorIndex - 1) + if (tempText.startsWith(" ")) { + text = tempText.makeStartWithSpace() + cursorIndex = oldCursorIndex - 1 // This [oldCursorIndex] is required since changing text might change the cursorIndex already in some circumstances + } else { + + } } } else { if (cursorIndex < text.length) { - text = text.withoutIndex(cursorIndex) + text = text.withoutIndex(cursorIndex).makeStartWithSpace() } } } @@ -529,3 +540,5 @@ class TextEditController( fun Text.editText(caretContainer: Container = this): TextEditController = TextEditController(this, caretContainer) + +fun String.makeStartWithSpace() = if (startsWith(" ")) this else " $this" \ No newline at end of file diff --git a/client/src/commonMain/kotlin/ui/custom/uiTextInput.kt b/client/src/commonMain/kotlin/ui/custom/uiTextInput.kt index c4e4dcd..e6d00cf 100644 --- a/client/src/commonMain/kotlin/ui/custom/uiTextInput.kt +++ b/client/src/commonMain/kotlin/ui/custom/uiTextInput.kt @@ -14,7 +14,7 @@ import korlibs.math.geom.* @KorgeExperimental inline fun Container.customUiTextInput( - initialText: String = "", + initialText: String = " ", size: Size = Size(128, 24), block: @ViewDslMarker UITextInput.() -> Unit = {} ): UITextInput = UITextInput(initialText, size) diff --git a/client/src/commonMain/kotlin/ui/waitingRoom.kt b/client/src/commonMain/kotlin/ui/waitingRoom.kt index d3c5d82..c4a779d 100644 --- a/client/src/commonMain/kotlin/ui/waitingRoom.kt +++ b/client/src/commonMain/kotlin/ui/waitingRoom.kt @@ -4,6 +4,7 @@ import korlibs.image.color.Colors import korlibs.image.text.HorizontalAlign import korlibs.image.text.TextAlignment import korlibs.korge.annotations.KorgeExperimental +import korlibs.korge.input.onClick import korlibs.korge.style.styles import korlibs.korge.style.textAlignment import korlibs.korge.ui.uiButton @@ -27,23 +28,27 @@ import kotlin.math.abs @OptIn(KorgeExperimental::class) suspend fun waitingRoom(room: UUID) { - sceneContainer.uiContainer { + lateinit var waitingRoom: View + waitingRoom = sceneContainer.uiContainer { val padding = 25f - val sidebarSize = Size(sceneContainer.width / 5f, sceneContainer.height) + val sidebarSize = Size(sceneContainer.width / 3.5f, sceneContainer.height) styles(styler) - uiText(getRoomName(room)) - .alignY(root, 0.075, true) + uiText(getRoomName(room)).position(padding, padding) val belowElementHeight = sceneContainer.width / 25f val leaveButton = Size(belowElementHeight*1.75f, belowElementHeight) val inputBarSize = Size(sceneContainer.width - sidebarSize.width - padding*2 - leaveButton.width - padding*2, belowElementHeight) customUiButton(size = leaveButton) { val back = solidRect(size, color = ColorPalette.out).centerOn(this) - customUiText("나가기").centerOn(this) + customUiText("나가기").centerOn(this).onClick { + waitingRoom.removeFromParent() + MainMenuState().mainMenu() + } positionX(padding) positionY(sceneContainer.height - padding - size.height) } uiContainer { val input = customUiTextInput(size = inputBarSize.minus(Size(padding/2, 0f))) { + text = " " styles { textAlignment = TextAlignment.MIDDLE_LEFT } controller.textView.alignment = TextAlignment.MIDDLE_LEFT controller.caretContainer.alignY(this, 0.75, false)