From 5f1ea4b098b4158388acb143a47bfc63643e52a1 Mon Sep 17 00:00:00 2001 From: Dave <16521341+davidmfritz@users.noreply.github.com> Date: Sat, 4 Jan 2020 18:39:57 +0100 Subject: [PATCH] UX improvements for showTextInput (#1290) * Added keyDown support for showTextInput (Enter, Escape, Back) * Removed unnecessary "this" * Added cursor autofocus on showTextInput --- core/src/mindustry/core/UI.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/core/UI.java b/core/src/mindustry/core/UI.java index 58cb23d802..f1b578cc9c 100644 --- a/core/src/mindustry/core/UI.java +++ b/core/src/mindustry/core/UI.java @@ -307,7 +307,19 @@ public class UI implements ApplicationListener, Loadable{ hide(); }).disabled(b -> field.getText().isEmpty()); buttons.addButton("$cancel", this::hide); - }}.show(); + keyDown(KeyCode.ENTER, () -> { + String text = field.getText(); + if(!text.isEmpty()){ + confirmed.get(text); + hide(); + } + }); + keyDown(KeyCode.ESCAPE, this::hide); + keyDown(KeyCode.BACK, this::hide); + show(); + Core.scene.setKeyboardFocus(field); + field.setCursorPosition(def.length()); + }}; } }