/** @return May be null. */ private TextField findNextTextField (Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor instanceof TextField) { if (actor == this) continue; TextField textField = (TextField)actor; if (textField.isDisabled() || !textField.focusTraversal || !textField.ancestorsVisible()) continue; Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); boolean below = actorCoords.y != currentCoords.y && (actorCoords.y < currentCoords.y ^ up); boolean right = actorCoords.y == currentCoords.y && (actorCoords.x > currentCoords.x ^ up); if (!below && !right) continue; boolean better = best == null || (actorCoords.y != bestCoords.y && (actorCoords.y > bestCoords.y ^ up)); if (!better) better = actorCoords.y == bestCoords.y && (actorCoords.x < bestCoords.x ^ up); if (better) { best = (TextField)actor; bestCoords.set(actorCoords); } } else if (actor instanceof Group) best = findNextTextField(((Group)actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
/** @return May be null. */ private TextField findNextTextField (Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor instanceof TextField) { if (actor == this) continue; TextField textField = (TextField)actor; if (textField.isDisabled() || !textField.focusTraversal || !textField.ancestorsVisible()) continue; Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); boolean below = actorCoords.y != currentCoords.y && (actorCoords.y < currentCoords.y ^ up); boolean right = actorCoords.y == currentCoords.y && (actorCoords.x > currentCoords.x ^ up); if (!below && !right) continue; boolean better = best == null || (actorCoords.y != bestCoords.y && (actorCoords.y > bestCoords.y ^ up)); if (!better) better = actorCoords.y == bestCoords.y && (actorCoords.x < bestCoords.x ^ up); if (better) { best = (TextField)actor; bestCoords.set(actorCoords); } } else if (actor instanceof Group) best = findNextTextField(((Group)actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
/** 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; TextField current = this; Vector2 currentCoords = current.getParent().localToStageCoordinates(tmp2.set(current.getX(), current.getY())); Vector2 bestCoords = tmp1; while (true) { TextField textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up); if (textField == null) { // Try to wrap around. if (up) currentCoords.set(Float.MIN_VALUE, Float.MIN_VALUE); else currentCoords.set(Float.MAX_VALUE, Float.MAX_VALUE); textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up); } if (textField == null) { Gdx.input.setOnscreenKeyboardVisible(false); break; } if (stage.setKeyboardFocus(textField)) { textField.selectAll(); break; } current = textField; currentCoords.set(bestCoords); } }
/** 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; TextField current = this; Vector2 currentCoords = current.getParent().localToStageCoordinates(tmp2.set(current.getX(), current.getY())); Vector2 bestCoords = tmp1; while (true) { TextField textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up); if (textField == null) { // Try to wrap around. if (up) currentCoords.set(Float.MIN_VALUE, Float.MIN_VALUE); else currentCoords.set(Float.MAX_VALUE, Float.MAX_VALUE); textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up); } if (textField == null) { Gdx.input.setOnscreenKeyboardVisible(false); break; } if (stage.setKeyboardFocus(textField)) { textField.selectAll(); break; } current = textField; currentCoords.set(bestCoords); } }
private TextField findNextTextField(Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor == this) continue; if (actor instanceof TextField) { TextField textField = (TextField) actor; if (textField.isDisabled() || !textField.focusTraversal) continue; Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); if ((actorCoords.y < currentCoords.y || (actorCoords.y == currentCoords.y && actorCoords.x > currentCoords.x)) ^ up) { if (best == null || (actorCoords.y > bestCoords.y || (actorCoords.y == bestCoords.y && actorCoords.x < bestCoords.x)) ^ up) { best = (TextField) actor; bestCoords.set(actorCoords); } } } else if (actor instanceof Group) best = findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
/** @return May be null. */ private TextField findNextTextField (Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor instanceof TextField) { if (actor == this) continue; TextField textField = (TextField)actor; if (textField.isDisabled() || !textField.focusTraversal || !textField.ancestorsVisible()) continue; Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); boolean below = actorCoords.y != currentCoords.y && (actorCoords.y < currentCoords.y ^ up); boolean right = actorCoords.y == currentCoords.y && (actorCoords.x > currentCoords.x ^ up); if (!below && !right) continue; boolean better = best == null || (actorCoords.y != bestCoords.y && (actorCoords.y > bestCoords.y ^ up)); if (!better) better = actorCoords.y == bestCoords.y && (actorCoords.x < bestCoords.x ^ up); if (better) { best = (TextField)actor; bestCoords.set(actorCoords); } } else if (actor instanceof Group) best = findNextTextField(((Group)actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
/** * 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); }
private VisTextField findNextTextField (Array<Actor> actors, VisTextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { Window modalWindow = findModalWindow(this); for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor == this) continue; if (actor instanceof VisTextField) { VisTextField textField = (VisTextField) actor; if (modalWindow != null) { Window nextFieldModalWindow = findModalWindow(textField); if (nextFieldModalWindow != modalWindow) continue; } if (textField.isDisabled() || !textField.focusTraversal || isActorVisibleInStage(textField) == false) continue; Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); if ((actorCoords.y < currentCoords.y || (actorCoords.y == currentCoords.y && actorCoords.x > currentCoords.x)) ^ up) { if (best == null || (actorCoords.y > bestCoords.y || (actorCoords.y == bestCoords.y && actorCoords.x < bestCoords.x)) ^ up) { best = (VisTextField) actor; bestCoords.set(actorCoords); } } } else if (actor instanceof Group) best = findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
/** 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())); TextField 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) stage.setKeyboardFocus(textField); else Gdx.input.setOnscreenKeyboardVisible(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; TextField current = this; Vector2 currentCoords = current.getParent().localToStageCoordinates(tmp2.set(current.getX(), current.getY())); Vector2 bestCoords = tmp1; while (true) { TextField textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up); if (textField == null) { // Try to wrap around. if (up) currentCoords.set(Float.MIN_VALUE, Float.MIN_VALUE); else currentCoords.set(Float.MAX_VALUE, Float.MAX_VALUE); textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up); } if (textField == null) { Gdx.input.setOnscreenKeyboardVisible(false); break; } if (stage.setKeyboardFocus(textField)) { textField.selectAll(); break; } current = textField; currentCoords.set(bestCoords); } }