v1.0.1: pressing enter now confirms single line text input
This commit is contained in:
@@ -71,11 +71,26 @@ public class TextInput extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!multiline){
|
||||||
|
textField.setTextFieldListener(new TextField.TextFieldListener(){
|
||||||
|
public void keyTyped (TextField textField, char c){
|
||||||
|
if (c == '\r' || c == '\n'){
|
||||||
|
enterPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
container.setActor(textField);
|
container.setActor(textField);
|
||||||
stage.setKeyboardFocus(textField);
|
stage.setKeyboardFocus(textField);
|
||||||
Gdx.input.setOnscreenKeyboardVisible(true);
|
Gdx.input.setOnscreenKeyboardVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enterPressed(){
|
||||||
|
//do nothing by default
|
||||||
|
};
|
||||||
|
|
||||||
public void setText(String text){
|
public void setText(String text){
|
||||||
textField.setText(text);
|
textField.setText(text);
|
||||||
textField.setCursorPosition(textField.getText().length());
|
textField.setCursorPosition(textField.getText().length());
|
||||||
|
|||||||
@@ -39,7 +39,14 @@ public class WndTextInput extends Window {
|
|||||||
add(txtTitle);
|
add(txtTitle);
|
||||||
|
|
||||||
int textSize = (int)PixelScene.uiCamera.zoom * (multiLine ? 6 : 9);
|
int textSize = (int)PixelScene.uiCamera.zoom * (multiLine ? 6 : 9);
|
||||||
TextInput textBox = new TextInput(Chrome.get(Chrome.Type.TOAST_WHITE), multiLine, textSize);
|
final TextInput textBox = new TextInput(Chrome.get(Chrome.Type.TOAST_WHITE), multiLine, textSize){
|
||||||
|
@Override
|
||||||
|
public void enterPressed() {
|
||||||
|
//triggers positive action on enter pressed, only with non-multiline though.
|
||||||
|
onSelect(true, getText());
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
if (initialValue != null) textBox.setText(initialValue);
|
if (initialValue != null) textBox.setText(initialValue);
|
||||||
textBox.setMaxLength(maxLength);
|
textBox.setMaxLength(maxLength);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user