@Override public void setDisabled (boolean disabled) { this.disabled = disabled; if (disabled) { FocusManager.resetFocus(getStage(), this); keyRepeatTask.cancel(); } }
/** Focuses this field, field must be added to stage before this method can be called */ public void focusField () { if (disabled) return; Stage stage = getStage(); FocusManager.switchFocus(stage, VisTextField.this); setCursorPosition(0); selectionStart = 0; //make sure textOffset was updated, prevent issue when there was long text selected and it was changed to short text //and field was focused. Without it textOffset would stay at max value and only one last letter will be visible in field calculateOffsets(); if (stage != null) stage.setKeyboardFocus(VisTextField.this); keyboard.show(true); hasSelection = true; }
@Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { if (!super.touchDown(event, x, y, pointer, button)) return false; if (pointer == 0 && button != 0) return false; if (disabled) return true; Stage stage = getStage(); FocusManager.switchFocus(stage, VisTextField.this); setCursorPosition(x, y); selectionStart = cursor; if (stage != null) stage.setKeyboardFocus(VisTextField.this); if (readOnly == false) keyboard.show(true); hasSelection = true; return true; }
Stage stage = getStage(); if (stage == null || stage.getKeyboardFocus() != VisTextField.this) return false;
/** * Focuses the next TextField. If none is found, the keyboard is hidden. Does nothing if the text field is not in a stage. * @param up If true, the TextField with the same or next smallest y coordinate is found, else the next highest. */ public void next (boolean up) { Stage stage = getStage(); if (stage == null) return; getParent().localToStageCoordinates(tmp1.set(getX(), getY())); VisTextField textField = findNextTextField(stage.getActors(), null, tmp2, tmp1, up); if (textField == null) { // Try to wrap around. if (up) tmp1.set(Float.MIN_VALUE, Float.MIN_VALUE); else tmp1.set(Float.MAX_VALUE, Float.MAX_VALUE); textField = findNextTextField(getStage().getActors(), null, tmp2, tmp1, up); } if (textField != null) { textField.focusField(); textField.setCursorPosition(textField.getText().length()); } else Gdx.input.setOnscreenKeyboardVisible(false); }
@Override public void draw (Batch batch, float parentAlpha) { Stage stage = getStage(); boolean focused = stage != null && stage.getKeyboardFocus() == this; if (!focused) keyRepeatTask.cancel();
cursorOn = false; Stage stage = getStage(); if (stage == null || stage.getKeyboardFocus() != VisTextField.this) return false; if (drawBorder == false) return false;