From 93692443b1c4ae3fa5034574c88da569d8b57875 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 4 Aug 2022 13:52:07 +0900 Subject: [PATCH] text centering on UIItemTextLineInput --- .../modulebasegame/ui/UIGraphicsControlPanel.kt | 2 +- src/net/torvald/terrarum/ui/UIItemTextLineInput.kt | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt index 109aca751..7032746ff 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt @@ -73,7 +73,7 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() { else if (args.startsWith("typeinres")) { val keyWidth = optionName.substringBefore(',') val keyHeight = optionName.substringAfter(',') - UIItemTextLineInput(this, x - spinnerWidth, y, spinnerWidth, { "${App.getConfigInt(keyWidth)}x${App.getConfigInt(keyHeight)}" }, InputLenCap(9, InputLenCap.CharLenUnit.CODEPOINTS), { it.headkey == Input.Keys.ENTER || it.headkey == Input.Keys.BACKSPACE || it.character?.matches(Regex("[0-9xX]")) == true }) to { it: UIItem, optionStr: String -> + UIItemTextLineInput(this, x - spinnerWidth, y, spinnerWidth, { "${App.getConfigInt(keyWidth)}x${App.getConfigInt(keyHeight)}" }, InputLenCap(9, InputLenCap.CharLenUnit.CODEPOINTS), { it.headkey == Input.Keys.ENTER || it.headkey == Input.Keys.BACKSPACE || it.character?.matches(Regex("[0-9xX]")) == true }, UIItemTextButton.Companion.Alignment.CENTRE) to { it: UIItem, optionStr: String -> (it as UIItemTextLineInput).textCommitListener = { text -> val text = text.lowercase() if (text.matches(Regex("""[0-9]+x[0-9]+"""))) { diff --git a/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt b/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt index 1703bf622..eaa2b2b8a 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt @@ -64,7 +64,8 @@ class UIItemTextLineInput( val maxLen: InputLenCap = InputLenCap(1000, InputLenCap.CharLenUnit.CODEPOINTS), // val enablePasteButton: Boolean = true, // val enableIMEButton: Boolean = true - var keyFilter: (TerrarumKeyboardEvent) -> Boolean = { true } + var keyFilter: (TerrarumKeyboardEvent) -> Boolean = { true }, + val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.LEFT, ) : UIItem(parentUI, initialX, initialY) { init { @@ -482,7 +483,12 @@ class UIItemTextLineInput( gdxClearAndSetBlend(0f, 0f, 0f, 0f) it.color = Color.WHITE - App.fontGameFBO.draw(it, if (textbuf.isEmpty()) currentPlaceholderText else textbuf, -1f*cursorDrawScroll, 0f) + + val text = if (textbuf.isEmpty()) currentPlaceholderText else textbuf + val tw = App.fontGameFBO.getWidth(text) + val offset = ((fbo.width - tw) / 2).coerceAtLeast(0) + + App.fontGameFBO.draw(it, text, -1f*cursorDrawScroll + offset, 0f) } } textCommitListener(getTextOrPlaceholder()) }