v2.5.0: improved text input performance regarding copy/paste

This commit is contained in:
Evan Debenham
2024-08-29 15:03:08 -04:00
parent 3aab646840
commit cc3c434d35
2 changed files with 58 additions and 10 deletions
@@ -90,6 +90,18 @@ public class WndTextInput extends Window {
onSelect(true, getText());
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);
textBox.setMaxLength(maxLength);
@@ -127,6 +139,7 @@ public class WndTextInput extends Window {
}
};
btnCopy.icon(Icons.COPY.get());
btnCopy.enable(!textBox.getText().isEmpty());
add(btnCopy);
btnPaste = new RedButton(""){
@@ -145,11 +158,16 @@ public class WndTextInput extends Window {
@Override
protected void onClick() {
super.onClick();
textBox.pasteFromClipboard();
if (Gdx.app.getClipboard().hasContents()) {
textBox.pasteFromClipboard();
} else {
enable(false);
}
}
};
btnPaste.icon(Icons.PASTE.get());
btnPaste.enable(Gdx.app.getClipboard().hasContents());
add(btnPaste);
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
public void offset(int xOffset, int yOffset) {
super.offset(xOffset, yOffset);