updateCursor();
return false;
}
private void updateCursor() {
TextRenderer textRenderer = textElement.getRenderer(TextRenderer.class);
String text = textField.getText();
checkBounds(text, textRenderer);
calcLastVisibleIndex(textRenderer);
// update text
if (isPassword(passwordChar)) {
int numChar = text.length();
char[] chars = new char[numChar];
for (int i = 0; i < numChar; ++i) {
chars[i] = passwordChar;
}
text = new String(chars);
}
textRenderer.setText(text);
textRenderer.setSelection(textField.getSelectionStart(), textField.getSelectionEnd());
// calc cursor position
int cursorPos = textField.getCursorPosition();
// outside, move window to fit cursorPos inside [first,last]
calcFirstVisibleIndex(cursorPos);
calcLastVisibleIndex(textRenderer);
String substring2 = text.substring(0, firstVisibleCharacterIndex);
int d = textRenderer.getFont().getWidth(substring2);
textRenderer.setXoffsetHack(-d);
String substring = text.substring(0, cursorPos);
int textWidth = textRenderer.getFont().getWidth(substring);
int cursorPixelPos = textWidth - d;
cursorElement.setConstraintX(new SizeValue(cursorPixelPos + "px"));
cursorElement.setConstraintY(new SizeValue((getElement().getHeight() - cursorElement.getHeight()) / 2 + CURSOR_Y + "px"));
cursorElement.startEffect(EffectEventId.onActive, null);