v1.4.0: implemented a copy and paste button for text input

This commit is contained in:
Evan Debenham
2022-08-11 16:56:49 -04:00
parent 7646489bc0
commit dcc84e4e7e
8 changed files with 127 additions and 19 deletions

View File

@@ -93,7 +93,6 @@ public class InputHandler extends InputAdapter {
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
ControllerHandler.setControllerPointer(false);
ControllerHandler.controllerActive = false;
Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it
if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) {
KeyEvent.addKeyEvent( new KeyEvent( button + 1000, true ) );

View File

@@ -21,6 +21,7 @@
package com.watabou.input;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.watabou.noosa.Game;
import com.watabou.noosa.ui.Cursor;
@@ -138,6 +139,8 @@ public class PointerEvent {
pointerEvents.add(event);
}
}
public static boolean clearKeyboardThisPress = true;
public static synchronized void processPointerEvents(){
//handle any hover events separately first as we may need to add drag events
@@ -164,6 +167,7 @@ public class PointerEvent {
if (p.type == Type.HOVER){
continue;
}
clearKeyboardThisPress = true;
if (activePointers.containsKey(p.id)){
PointerEvent existing = activePointers.get(p.id);
existing.current = p.current;
@@ -181,6 +185,10 @@ public class PointerEvent {
}
pointerSignal.dispatch(p);
}
if (clearKeyboardThisPress){
//most press events should clear the keyboard
Gdx.input.setOnscreenKeyboardVisible(false);
}
}
pointerEvents.clear();
}

View File

@@ -126,6 +126,31 @@ public class TextInput extends Component {
return textField.getText();
}
public void copyToClipboard(){
if (textField.getSelection().isEmpty()) {
textField.selectAll();
}
textField.copy();
}
public void pasteFromClipboard(){
if (!Gdx.app.getClipboard().hasContents()) return;
if (!textField.getSelection().isEmpty()){
//just use cut, but override clipboard
String existingClip = Gdx.app.getClipboard().getContents();
textField.cut();
Gdx.app.getClipboard().setContents(existingClip);
}
String existing = textField.getText();
int cursorIdx = textField.getCursorPosition();
textField.setText(existing.substring(0, cursorIdx) + Gdx.app.getClipboard().getContents() + existing.substring(cursorIdx));
textField.setCursorPosition(cursorIdx + Gdx.app.getClipboard().getContents().length());
}
@Override
protected void layout() {
super.layout();