v2.5.0: improved text input performance regarding copy/paste
This commit is contained in:
@@ -76,7 +76,35 @@ public class TextInput extends Component {
|
|||||||
TextField.TextFieldStyle style = skin.get(TextField.TextFieldStyle.class);
|
TextField.TextFieldStyle style = skin.get(TextField.TextFieldStyle.class);
|
||||||
style.font = Game.platform.getFont(size, "", false, false);
|
style.font = Game.platform.getFont(size, "", false, false);
|
||||||
style.background = null;
|
style.background = null;
|
||||||
textField = multiline ? new TextArea("", style) : new TextField("", style);
|
if (multiline){
|
||||||
|
textField = new TextArea("", style){
|
||||||
|
@Override
|
||||||
|
public void cut() {
|
||||||
|
super.cut();
|
||||||
|
onClipBoardUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy() {
|
||||||
|
super.copy();
|
||||||
|
onClipBoardUpdate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
textField = new TextField("", style){
|
||||||
|
@Override
|
||||||
|
public void cut() {
|
||||||
|
super.cut();
|
||||||
|
onClipBoardUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy() {
|
||||||
|
super.copy();
|
||||||
|
onClipBoardUpdate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
textField.setProgrammaticChangeEvents(true);
|
textField.setProgrammaticChangeEvents(true);
|
||||||
|
|
||||||
if (!multiline) textField.setAlignment(Align.center);
|
if (!multiline) textField.setAlignment(Align.center);
|
||||||
@@ -90,6 +118,7 @@ public class TextInput extends Component {
|
|||||||
style.font = f;
|
style.font = f;
|
||||||
textField.setStyle(style);
|
textField.setStyle(style);
|
||||||
}
|
}
|
||||||
|
onChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -117,9 +146,17 @@ public class TextInput extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void enterPressed(){
|
public void enterPressed(){
|
||||||
//do nothing by default
|
//fires any time enter is pressed, do nothing by default
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void onChanged(){
|
||||||
|
//fires any time the text box is changed, do nothing by default
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClipBoardUpdate(){
|
||||||
|
//fires any time the clipboard is updated via cut or copy, 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());
|
||||||
|
|||||||
@@ -90,6 +90,18 @@ public class WndTextInput extends Window {
|
|||||||
onSelect(true, getText());
|
onSelect(true, getText());
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChanged() {
|
||||||
|
super.onChanged();
|
||||||
|
if (btnCopy != null) btnCopy.enable(!getText().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClipBoardUpdate() {
|
||||||
|
super.onClipBoardUpdate();
|
||||||
|
btnPaste.enable(Gdx.app.getClipboard().hasContents());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if (initialValue != null) textBox.setText(initialValue);
|
if (initialValue != null) textBox.setText(initialValue);
|
||||||
textBox.setMaxLength(maxLength);
|
textBox.setMaxLength(maxLength);
|
||||||
@@ -127,6 +139,7 @@ public class WndTextInput extends Window {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
btnCopy.icon(Icons.COPY.get());
|
btnCopy.icon(Icons.COPY.get());
|
||||||
|
btnCopy.enable(!textBox.getText().isEmpty());
|
||||||
add(btnCopy);
|
add(btnCopy);
|
||||||
|
|
||||||
btnPaste = new RedButton(""){
|
btnPaste = new RedButton(""){
|
||||||
@@ -145,11 +158,16 @@ public class WndTextInput extends Window {
|
|||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
super.onClick();
|
super.onClick();
|
||||||
textBox.pasteFromClipboard();
|
if (Gdx.app.getClipboard().hasContents()) {
|
||||||
|
textBox.pasteFromClipboard();
|
||||||
|
} else {
|
||||||
|
enable(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
btnPaste.icon(Icons.PASTE.get());
|
btnPaste.icon(Icons.PASTE.get());
|
||||||
|
btnPaste.enable(Gdx.app.getClipboard().hasContents());
|
||||||
add(btnPaste);
|
add(btnPaste);
|
||||||
|
|
||||||
btnCopy.setRect(textBoxWidth + 2*MARGIN, pos, BUTTON_HEIGHT, BUTTON_HEIGHT);
|
btnCopy.setRect(textBoxWidth + 2*MARGIN, pos, BUTTON_HEIGHT, BUTTON_HEIGHT);
|
||||||
@@ -200,13 +218,6 @@ public class WndTextInput extends Window {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void update() {
|
|
||||||
super.update();
|
|
||||||
btnCopy.enable(!textBox.getText().isEmpty());
|
|
||||||
btnPaste.enable(Gdx.app.getClipboard().hasContents());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void offset(int xOffset, int yOffset) {
|
public void offset(int xOffset, int yOffset) {
|
||||||
super.offset(xOffset, yOffset);
|
super.offset(xOffset, yOffset);
|
||||||
|
|||||||
Reference in New Issue
Block a user