Package arc.scene.ui
Class TextField
java.lang.Object
arc.scene.Element
arc.scene.ui.TextField
- All Implemented Interfaces:
Disableable
- Direct Known Subclasses:
TextArea
A single-line text input field.
The preferred height of a text field is the height of the TextField.TextFieldStyle.font
and TextField.TextFieldStyle.background
.
The preferred width of a text field is 150, a relatively arbitrary size.
The text field will copy the currently selected text when ctrl+c is pressed, and paste any text in the clipboard when ctrl+v is pressed. Clipboard functionality is provided via the Clipboard interface. Currently there are two standard implementations, one for the desktop and one for Android. The Android clipboard is a stub, as copy & pasting on Android is not supported yet.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Basic input listener for the text fieldstatic interface
Interface for filtering characters entered into the text field.static interface
Interface for listening to typed characters.static class
The style for a text field, seeTextField
.static interface
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final char
protected float
protected static final char
protected int
protected boolean
protected static final char
protected boolean
protected CharSequence
protected TextField.TextFieldFilter
protected boolean
protected float
protected final FloatSeq
protected boolean
protected boolean
Special field containing implementation-specific data for IME support.protected InputListener
protected InputListener
static float
protected arc.scene.ui.TextField.KeyRepeatTask
static float
protected long
protected long
protected final GlyphLayout
protected TextField.TextFieldListener
protected int
protected String
protected boolean
protected StringBuilder
protected char
protected boolean
protected boolean
protected float
protected int
protected float
protected float
protected TextField.TextFieldStyle
protected static final char
protected String
protected int
protected float
protected float
protected String
protected TextField.TextFieldValidator
protected int
protected int
protected boolean
Fields inherited from class arc.scene.Element
color, cullable, fillParent, height, name, originX, originY, parent, parentAlpha, rotation, scaleX, scaleY, touchable, touchablility, translation, userObject, visibility, visible, width, x, y
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
appendText
(String str) protected void
void
void
protected boolean
continueCursor
(int index, int offset) void
copy()
Copies the contents of this TextField to the lipboard implementation set on this TextField.protected InputListener
void
cut()
Copies the selected contents of this TextField to the Clipboard implementation set on this TextField, then removes it.void
draw()
Draws the element.protected void
drawCursor
(Drawable cursorPatch, Font font, float x, float y) protected void
drawSelection
(Drawable selection, Font font, float x, float y) Draws selection rectangleprotected void
int
int
float
float
boolean
int
getStyle()
Returns the text field's style.getText()
protected float
protected void
boolean
boolean
boolean
isValid()
protected boolean
isWordCharacter
(char c) protected int
letterUnderCursor
(float x) protected void
moveCursor
(boolean forward, boolean jump) void
next
(boolean up) Focuses the next TextField.void
void
void
void
setAlignment
(int alignment) Sets text horizontal alignment (left, center or right).void
setBlinkTime
(float blinkTime) void
setCursorPosition
(int cursorPosition) Sets the cursor position and clears any selection.void
setDisabled
(boolean disabled) void
setFilter
(TextField.TextFieldFilter filter) void
setFocusTraversal
(boolean focusTraversal) If true (the default), tab/shift+tab will move to the next text field.void
setMaxLength
(int maxLength) void
setMessageText
(String messageText) Sets the text that will be drawn in the text field if no text has been entered.void
setOnlyFontChars
(boolean onlyFontChars) When false, text set bysetText(String)
may contain characters not in the font, a space will be displayed instead.void
setPasswordCharacter
(char passwordCharacter) Sets the password character for the text field.void
setPasswordMode
(boolean passwordMode) If true, the text in this text field will be shown as bullet characters.void
setProgrammaticChangeEvents
(boolean programmaticChangeEvents) If false, methods that change the text will not fireChangeListener.ChangeEvent
, the event will be fired only when user changes the text.void
setSelection
(int selectionStart, int selectionEnd) Sets the selected text.void
setStyle
(TextField.TextFieldStyle style) void
void
void
setValidator
(TextField.TextFieldValidator validator) void
void
protected void
protected int[]
wordUnderCursor
(int at) Methods inherited from class arc.scene.Element
act, actions, addAction, addCaptureListener, addListener, change, changed, clear, clearActions, clearListeners, clicked, clicked, clicked, clicked, clipBegin, clipBegin, clipEnd, dragged, exited, fire, fireClick, getActions, getCaptureListeners, getHeight, getListeners, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getRight, getRotation, getScene, getTop, getWidth, getX, getY, getZIndex, hasActions, hasKeyboard, hasMouse, hasParent, hasScroll, hit, hovered, invalidate, invalidateHierarchy, isAscendantOf, isDescendantOf, isDescendantOf, isTouchable, keepInStage, keyDown, keyDown, layout, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, needsLayout, notify, pack, parentToLocalCoordinates, released, remove, removeAction, removeCaptureListener, removeListener, requestKeyboard, requestScroll, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, scrolled, setBounds, setColor, setColor, setFillParent, setHeight, setLayoutEnabled, setOrigin, setOrigin, setPosition, setPosition, setRotation, setRotationOrigin, setScale, setScale, setScene, setSize, setSize, setTranslation, setWidth, setZIndex, sizeBy, sizeBy, sizeChanged, stageToLocalCoordinates, tapped, toBack, toFront, toString, touchable, update, updateVisibility, validate, visible
-
Field Details
-
BACKSPACE
protected static final char BACKSPACE- See Also:
-
TAB
protected static final char TAB- See Also:
-
DELETE
protected static final char DELETE- See Also:
-
BULLET
protected static final char BULLET- See Also:
-
keyRepeatInitialTime
public static float keyRepeatInitialTime -
keyRepeatTime
public static float keyRepeatTime -
imeData
Special field containing implementation-specific data for IME support. -
layout
-
glyphPositions
-
text
-
cursor
protected int cursor -
selectionStart
protected int selectionStart -
hasSelection
protected boolean hasSelection -
writeEnters
protected boolean writeEnters -
displayText
-
fontOffset
protected float fontOffset -
textHeight
protected float textHeight -
textOffset
protected float textOffset -
inputDialogListener
-
style
-
inputListener
-
listener
-
validator
-
filter
-
focusTraversal
protected boolean focusTraversal -
onlyFontChars
protected boolean onlyFontChars -
disabled
protected boolean disabled -
undoText
-
lastChangeTime
protected long lastChangeTime -
passwordMode
protected boolean passwordMode -
renderOffset
protected float renderOffset -
cursorOn
protected boolean cursorOn -
hasInputDialog
protected boolean hasInputDialog -
lastBlink
protected long lastBlink -
keyRepeatTask
protected arc.scene.ui.TextField.KeyRepeatTask keyRepeatTask -
programmaticChangeEvents
protected boolean programmaticChangeEvents -
messageText
-
textHAlign
protected int textHAlign -
selectionX
protected float selectionX -
selectionWidth
protected float selectionWidth -
passwordBuffer
-
passwordCharacter
protected char passwordCharacter -
visibleTextStart
protected int visibleTextStart -
visibleTextEnd
protected int visibleTextEnd -
maxLength
protected int maxLength -
blinkTime
protected float blinkTime
-
-
Constructor Details
-
TextField
public TextField() -
TextField
-
TextField
-
-
Method Details
-
initialize
protected void initialize() -
createInputListener
-
letterUnderCursor
protected int letterUnderCursor(float x) -
isWordCharacter
protected boolean isWordCharacter(char c) -
wordUnderCursor
protected int[] wordUnderCursor(int at) -
removeInputDialog
public void removeInputDialog() -
addInputDialog
public void addInputDialog() -
getMaxLength
public int getMaxLength() -
setMaxLength
public void setMaxLength(int maxLength) -
clearText
public void clearText() -
setOnlyFontChars
public void setOnlyFontChars(boolean onlyFontChars) When false, text set bysetText(String)
may contain characters not in the font, a space will be displayed instead. When true (the default), characters not in the font are stripped by setText. Characters not in the font are always stripped when typed or pasted. -
getStyle
Returns the text field's style. Modifying the returned style may not have an effect untilsetStyle(TextFieldStyle)
is called. -
setStyle
-
calculateOffsets
protected void calculateOffsets() -
draw
public void draw()Description copied from class:Element
Draws the element. Does nothing by default. -
isValid
public boolean isValid() -
getTextY
-
drawSelection
Draws selection rectangle -
drawText
-
drawCursor
-
updateDisplayText
protected void updateDisplayText() -
copy
public void copy()Copies the contents of this TextField to the lipboard implementation set on this TextField. -
cut
public void cut()Copies the selected contents of this TextField to the Clipboard implementation set on this TextField, then removes it. -
paste
-
next
public void next(boolean up) Focuses the next TextField. If none is found, the keyboard is hidden. Does nothing if the text field is not in a stage.- Parameters:
up
- If true, the TextField with the same or next smallest y coordinate is found, else the next highest.
-
getDefaultInputListener
-
setTextFieldListener
- Parameters:
listener
- May be null.
-
typed
-
typed
-
getFilter
-
setFilter
- Parameters:
filter
- May be null.
-
setValidator
-
getValidator
-
setFocusTraversal
public void setFocusTraversal(boolean focusTraversal) If true (the default), tab/shift+tab will move to the next text field. -
getMessageText
- Returns:
- May be null.
-
setMessageText
Sets the text that will be drawn in the text field if no text has been entered.- Parameters:
messageText
- may be null.
-
appendText
- Parameters:
str
- If null, "" is used.
-
getText
- Returns:
- Never null, might be an empty string.
-
setText
- Parameters:
str
- If null, "" is used.
-
getProgrammaticChangeEvents
public boolean getProgrammaticChangeEvents() -
setProgrammaticChangeEvents
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents) If false, methods that change the text will not fireChangeListener.ChangeEvent
, the event will be fired only when user changes the text. -
getSelectionStart
public int getSelectionStart() -
getSelection
-
setSelection
public void setSelection(int selectionStart, int selectionEnd) Sets the selected text. -
selectAll
public void selectAll() -
clearSelection
public void clearSelection() -
getCursorPosition
public int getCursorPosition() -
setCursorPosition
public void setCursorPosition(int cursorPosition) Sets the cursor position and clears any selection. -
getPrefWidth
public float getPrefWidth()- Overrides:
getPrefWidth
in classElement
-
getPrefHeight
public float getPrefHeight()- Overrides:
getPrefHeight
in classElement
-
setAlignment
public void setAlignment(int alignment) Sets text horizontal alignment (left, center or right).- See Also:
-
isPasswordMode
public boolean isPasswordMode() -
setPasswordMode
public void setPasswordMode(boolean passwordMode) If true, the text in this text field will be shown as bullet characters.- See Also:
-
setPasswordCharacter
public void setPasswordCharacter(char passwordCharacter) Sets the password character for the text field. The character must be present in theFont
. Default is 149 (bullet). -
setBlinkTime
public void setBlinkTime(float blinkTime) -
isDisabled
public boolean isDisabled()- Specified by:
isDisabled
in interfaceDisableable
-
setDisabled
public void setDisabled(boolean disabled) - Specified by:
setDisabled
in interfaceDisableable
-
moveCursor
protected void moveCursor(boolean forward, boolean jump) -
continueCursor
protected boolean continueCursor(int index, int offset)
-