@Override public String toString () { return getText(); }
public VisTextField (String text, VisTextFieldStyle style) { setStyle(style); clipboard = Gdx.app.getClipboard(); initialize(); setText(text); setSize(getPrefWidth(), getPrefHeight()); }
protected void initialize () { addListener(inputListener = createInputListener()); addListener(clickListener = new ClickListener() { @Override public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) { super.enter(event, x, y, pointer, fromActor); if (pointer == -1 && isDisabled() == false) { Gdx.graphics.setSystemCursor(SystemCursor.Ibeam); } } @Override public void exit (InputEvent event, float x, float y, int pointer, Actor toActor) { super.exit(event, x, y, pointer, toActor); if (pointer == -1) { CursorManager.restoreDefaultCursor(); } } }); }
@Override public void changed (ChangeEvent event, Actor actor) { fileNameField.setText(arbitraryPath); fileNameField.setCursorAtTextEnd(); } });
public void setCursorAtTextEnd () { setCursorPosition(0); calculateOffsets(); setCursorPosition(getText().length()); }
/** @param selectText if true text will be selected (this can be useful if you want to allow user quickly erase all text). */ public InputDialog setText (String text, boolean selectText) { field.setText(text); field.setCursorPosition(text.length()); if (selectText) { field.selectAll(); } return this; }
@Override public void draw (Batch batch, float parentAlpha) { Stage stage = getStage(); boolean focused = stage != null && stage.getKeyboardFocus() == this; if (!focused) keyRepeatTask.cancel(); Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); float textY = getTextY(font, background); calculateOffsets(); drawSelection(selection, batch, font, x + bgLeftWidth, y + textY); drawText(batch, font, x + bgLeftWidth, y + textY + yOffset); blink(); if (cursorOn && cursorPatch != null) { drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY); if (isDisabled() == false && inputValid == false && style.errorBorder != null) style.errorBorder.draw(batch, getX(), getY(), getWidth(), getHeight()); else if (focusBorderEnabled && drawBorder && style.focusBorder != null) style.focusBorder.draw(batch, getX(), getY(), getWidth(), getHeight());
Stage stage = getStage(); if (stage == null || stage.getKeyboardFocus() != VisTextField.this) return false; if (drawBorder == false) return false; paste(clipboard.getContents(), true); repeat = true; copy(); return true; cut(true); return true; selectAll(); return true; int oldCursorPos = getCursorPosition(); setText(undoText); VisTextField.this.setCursorPosition(MathUtils.clamp(cursor, 0, undoText.length())); undoText = oldText; undoCursorPos = oldCursorPos; updateDisplayText(); return true; if (keycode == Keys.INSERT && readOnly == false) paste(clipboard.getContents(), true); if (keycode == Keys.FORWARD_DEL && readOnly == false) cut(true); selection: moveCursor(false, jump);
/** * 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); }
edtName.focusField(); edtName.setText(sourcePack.getName()); edtName.selectAll(); edtName.addListener(new InputListener() { @Override public boolean keyDown(InputEvent event, int keycode) {
/** Clears VisTextField text. If programmatic change events are disabled then this will not fire change event. */ public void clearText () { setText(""); }
@Override public boolean acceptChar (VisTextField field, char c) { int selectionStart = field.getSelectionStart(); int cursorPos = field.getCursorPosition(); String text; if (field.isTextSelected()) { //issue #131 String beforeSelection = field.getText().substring(0, Math.min(selectionStart, cursorPos)); String afterSelection = field.getText().substring(Math.max(selectionStart, cursorPos)); text = beforeSelection + afterSelection; } else { text = field.getText(); } if (c == '.' && text.contains(".") == false) return true; return super.acceptChar(field, c); } }
private void createFileTextBox () { VisTable table = new VisTable(true); VisLabel nameLabel = new VisLabel(FILE_NAME.get()); selectedFileTextField = new VisTextField(); selectedFileTextField.setProgrammaticChangeEvents(false); .spaceBottom(new ConstantIfVisibleValue(sizes.spacingBottom)).expand().fill(); selectedFileTextField.addListener(new InputListener() { @Override public boolean keyDown (InputEvent event, int keycode) { selectedFileTextField.addListener(new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) {
VisTextField normalTextField = new VisTextField("textbox"); VisTextField disabledTextField = new VisTextField("disabled"); VisTextField passwordTextField = new VisTextField("password"); VisTextField invalidTextField = new VisTextField("invalid"); disabledTextField.setDisabled(true); passwordTextField.setPasswordMode(true); invalidTextField.setInputValid(false);
@Override public void clicked (InputEvent event, float x, float y) { int count = getTapCount() % 4; if (count == 0) clearSelection(); if (count == 2) { int[] array = wordUnderCursor(x); setSelection(array[0], array[1]); } if (count == 3) selectAll(); }
public TextFieldWithLabel(String labelText, int width) { super(); this.width = width; textField = new VisTextField(); label = new VisLabel(labelText); setupUI(); }
private void buildFileList (Array<FileHandle> files, IdentityMap<FileHandle, FileHandleMetadata> metadata, FileHandle[] selectedFiles, boolean stageChanged) { currentFiles.clear(); currentFilesMetadata.clear(); showBusyBarTask.cancel(); fileListBusyBar.setVisible(false); if (files.size == 0) { fileListAdapter.itemsChanged(); return; } maxDateLabelWidth = 0; currentFiles.addAll(files); currentFilesMetadata = metadata; fileListAdapter.itemsChanged(); fileListView.getScrollPane().setScrollX(0); fileListView.getScrollPane().setScrollY(0); highlightFiles(selectedFiles); if (stageChanged && selectedFiles.length == 0 && defaultFileName != null) { selectedFileTextField.setText(defaultFileName); FileHandle enteredFile = currentDirectory.child(selectedFileTextField.getText()); if (currentFiles.contains(enteredFile, false)) { highlightFiles(enteredFile); } } }
actorsPacks.edtOutputDir.setText(pack.getOutputDir()); actorsPacks.edtFileName.setText(pack.getFilename()); actorsPacks.edtFileName.setMessageText(pack.getName() + ".atlas"); } else { actorsPacks.edtOutputDir.setText(null); actorsPacks.edtFileName.setText(null);
@OnEvent(PackPropertyChangedEvent.class) void onEvent(PackPropertyChangedEvent event) { if (viewShown) { switch (event.getProperty()) { case NAME: case SCALE_FACTORS: if (event.getPack() == getSelectedPack()) { updateViewsFromPack(event.getPack()); } break; case OUTPUT: if (event.getPack() == getSelectedPack()) { actorsPacks.edtOutputDir.setProgrammaticChangeEvents(false); actorsPacks.edtOutputDir.setText(event.getPack().getOutputDir()); actorsPacks.edtOutputDir.setProgrammaticChangeEvents(true); } break; case FILENAME: if (event.getPack() == getSelectedPack()) { actorsPacks.edtFileName.setProgrammaticChangeEvents(false); actorsPacks.edtFileName.setText(event.getPack().getFilename()); actorsPacks.edtFileName.setProgrammaticChangeEvents(true); } break; } } }
currentPath = new VisTextField(); final VisImageButton showRecentDirButton = new VisImageButton(style.expandDropdown); showRecentDirButton.setFocusBorderEnabled(false); currentPath.addListener(new InputListener() { @Override public boolean keyTyped (InputEvent event, char character) { currentPath.addListener(new FocusListener() { @Override public void keyboardFocusChanged (FocusEvent event, Actor actor, boolean focused) {