Class TextraField
- All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Disableable
,com.badlogic.gdx.scenes.scene2d.utils.Layout
- Direct Known Subclasses:
TextraArea
This class is beta-quality right now! You can try alternatives instead of using TextraField:
When you want text entry, you should use a
TextField
with a
BitmapFont
that has its
BitmapFont.BitmapFontData.markupEnabled
set to false.
If you just want a span of read-only text that can be selected and copied, then use a
TypingLabel
with
selectable
set to true, use a TypingListener
that checks for the
event "*SELECTED"
, and call TypingLabel.copySelectedText()
when the user requests.
NONE OF THE REST OF THIS IS ACCURATE YET.
The preferred height of a text field is the height of the
Styles.TextFieldStyle.font
and Styles.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-and-pasting on Android is not
supported yet.
The text field allows you to specify an TextraField.OnscreenKeyboard
for displaying a softkeyboard and piping all key events
generated by the keyboard to the text field. There are two standard implementations, one for the desktop and one for Android.
The desktop keyboard is a stub, as a softkeyboard is not needed on the desktop. The Android TextraField.OnscreenKeyboard
implementation will bring up the default IME.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The defaultTextraField.OnscreenKeyboard
used by allTextraField
instances.protected class
static interface
An interface for onscreen keyboards.class
Basic input listener for the TextraFieldstatic interface
Interface for filtering characters entered into the text field.static interface
Interface for listening to typed characters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final char
protected boolean
protected final com.badlogic.gdx.utils.Timer.Task
protected float
static final char
Used as the default char to replace content whenpasswordMode
is on.protected static final char
protected com.badlogic.gdx.utils.Clipboard
protected int
protected boolean
protected static final char
protected boolean
protected TextraField.TextFieldFilter
protected boolean
protected boolean
protected float
protected final com.badlogic.gdx.utils.FloatArray
protected com.badlogic.gdx.scenes.scene2d.InputListener
protected TextraField.OnscreenKeyboard
static float
protected final TextraField.KeyRepeatTask
static float
protected TypingLabel
protected long
protected TextraField.TextFieldListener
protected int
protected String
protected static final char
protected boolean
protected char
protected boolean
protected boolean
protected float
protected boolean
protected Styles.TextFieldStyle
protected static final char
protected String
protected int
protected float
protected String
protected int
protected int
protected boolean
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Only meant for subclasses; requires everything used in TextraField to be initialized by the subclass.TextraField
(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin) TextraField
(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, Font replacementFont) TextraField
(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName) TextraField
(String text, Styles.TextFieldStyle style) TextraField
(String text, Styles.TextFieldStyle style, Font replacementFont) -
Method Summary
Modifier and TypeMethodDescriptionvoid
act
(float delta) void
appendText
(String str) protected void
void
protected boolean
continueCursor
(int index, int offset) void
copy()
Copies the contents of this TextraField to theClipboard
implementation set on this TextraField.protected com.badlogic.gdx.scenes.scene2d.InputListener
void
cut()
Copies the selected contents of this TextraField to theClipboard
implementation set on this TextraField, then removes it.protected void
cut
(boolean fireChangeEvent) protected int
delete
(boolean fireChangeEvent) void
draw
(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) protected void
drawCursor
(com.badlogic.gdx.scenes.scene2d.utils.Drawable cursorPatch, com.badlogic.gdx.graphics.g2d.Batch batch, Font font, float x, float y) int
protected com.badlogic.gdx.scenes.scene2d.utils.Drawable
float
int
com.badlogic.gdx.scenes.scene2d.InputListener
int
Default is an instance ofTextraField.DefaultOnscreenKeyboard
.char
Gets the password character for the text field.float
float
boolean
int
int
getStyle()
Returns the text field's style.getText()
protected float
protected void
protected boolean
insert
(int position, CharSequence inserting) protected String
insert
(int position, CharSequence text, String to) boolean
boolean
boolean
protected boolean
isSpaceCharacter
(char c) protected boolean
isSpaceCharacter
(long glyph) protected boolean
isWordCharacter
(char c) protected boolean
isWordCharacter
(long glyph) protected void
moveCursor
(boolean forward, boolean jump) void
next
(boolean up) Sets thekeyboard focus
to the next TextraField.protected void
protected void
void
void
setAlignment
(int alignment) Sets text horizontal alignment (left, center or right).void
setBlinkTime
(float blinkTime) void
setClipboard
(com.badlogic.gdx.utils.Clipboard clipboard) void
setCursorBlinking
(boolean blinkEnabled) void
setCursorPosition
(int cursorPosition) Sets the cursor position and clears any selection.void
setDisabled
(boolean disabled) 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
protected void
setParent
(com.badlogic.gdx.scenes.scene2d.Group parent) 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 the user changes the text.void
setSelection
(int selectionStart, int selectionEnd) Sets the selected text.protected void
setStage
(com.badlogic.gdx.scenes.scene2d.Stage stage) void
setStyle
(Styles.TextFieldStyle style) void
void
void
protected void
protected long
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, layout, needsLayout, pack, setFillParent, setLayoutEnabled, validate
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, drawDebugBounds, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, hit, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
-
Field Details
-
BACKSPACE
protected static final char BACKSPACE- See Also:
-
CARRIAGE_RETURN
protected static final char CARRIAGE_RETURN- See Also:
-
NEWLINE
protected static final char NEWLINE- See Also:
-
TAB
protected static final char TAB- See Also:
-
DELETE
protected static final char DELETE- See Also:
-
BULLET
public static final char BULLETUsed as the default char to replace content whenpasswordMode
is on.- See Also:
-
keyRepeatInitialTime
public static float keyRepeatInitialTime -
keyRepeatTime
public static float keyRepeatTime -
text
-
cursor
protected int cursor -
writeEnters
protected boolean writeEnters -
label
-
glyphPositions
protected final com.badlogic.gdx.utils.FloatArray glyphPositions -
style
-
messageText
-
showingMessage
protected boolean showingMessage -
clipboard
protected com.badlogic.gdx.utils.Clipboard clipboard -
inputListener
protected com.badlogic.gdx.scenes.scene2d.InputListener inputListener -
listener
-
filter
-
keyboard
-
focusTraversal
protected boolean focusTraversal -
onlyFontChars
protected boolean onlyFontChars -
disabled
protected boolean disabled -
textHAlign
protected int textHAlign -
undoText
-
lastChangeTime
protected long lastChangeTime -
passwordMode
protected boolean passwordMode -
passwordCharacter
protected char passwordCharacter -
fontOffset
protected float fontOffset -
textOffset
protected float textOffset -
renderOffset
protected float renderOffset -
visibleTextStart
protected int visibleTextStart -
visibleTextEnd
protected int visibleTextEnd -
maxLength
protected int maxLength -
focused
protected boolean focused -
cursorOn
protected boolean cursorOn -
blinkEnabled
protected boolean blinkEnabled -
blinkTime
protected float blinkTime -
blinkTask
protected final com.badlogic.gdx.utils.Timer.Task blinkTask -
keyRepeatTask
-
programmaticChangeEvents
protected boolean programmaticChangeEvents
-
-
Constructor Details
-
TextraField
protected TextraField()Only meant for subclasses; requires everything used in TextraField to be initialized by the subclass. -
TextraField
-
TextraField
-
TextraField
-
TextraField
-
TextraField
-
-
Method Details
-
setStage
protected void setStage(com.badlogic.gdx.scenes.scene2d.Stage stage) - Overrides:
setStage
in classcom.badlogic.gdx.scenes.scene2d.Actor
-
setParent
protected void setParent(com.badlogic.gdx.scenes.scene2d.Group parent) - Overrides:
setParent
in classcom.badlogic.gdx.scenes.scene2d.Actor
-
initialize
protected void initialize() -
createInputListener
protected com.badlogic.gdx.scenes.scene2d.InputListener createInputListener() -
isWordCharacter
protected boolean isWordCharacter(char c) -
isWordCharacter
protected boolean isWordCharacter(long glyph) -
isSpaceCharacter
protected boolean isSpaceCharacter(char c) -
isSpaceCharacter
protected boolean isSpaceCharacter(long glyph) -
wordUnderCursor
protected long wordUnderCursor() -
setMaxLength
public void setMaxLength(int maxLength) -
getMaxLength
public int getMaxLength() -
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. -
setStyle
-
getStyle
Returns the text field's style. Modifying the returned style may not have an effect untilsetStyle(TextFieldStyle)
is called. -
calculateOffsets
protected void calculateOffsets() -
getBackgroundDrawable
@Null protected com.badlogic.gdx.scenes.scene2d.utils.Drawable getBackgroundDrawable() -
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) - Overrides:
draw
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getTextY
protected float getTextY(Font font, @Null com.badlogic.gdx.scenes.scene2d.utils.Drawable background) -
drawCursor
protected void drawCursor(com.badlogic.gdx.scenes.scene2d.utils.Drawable cursorPatch, com.badlogic.gdx.graphics.g2d.Batch batch, Font font, float x, float y) -
copy
public void copy()Copies the contents of this TextraField to theClipboard
implementation set on this TextraField. -
cut
public void cut()Copies the selected contents of this TextraField to theClipboard
implementation set on this TextraField, then removes it. -
cut
protected void cut(boolean fireChangeEvent) -
paste
-
insert
-
insert
-
delete
protected int delete(boolean fireChangeEvent) -
next
public void next(boolean up) Sets thekeyboard focus
to the next TextraField. If no next text field is found, the onscreen keyboard is hidden. Does nothing if the text field is not in a stage.- Parameters:
up
- If true, the text field with the same or next smallest y coordinate is found, else the next highest.
-
getDefaultInputListener
public com.badlogic.gdx.scenes.scene2d.InputListener getDefaultInputListener() -
setTextFieldListener
- Parameters:
listener
- May be null.
-
setTextFieldFilter
- Parameters:
filter
- May be null.
-
getTextFieldFilter
-
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.
-
setText
- Parameters:
str
- If null, "" is used.
-
getText
- Returns:
- Never null, might be an empty string.
-
setProgrammaticChangeEvents
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents) If false, methods that change the text will not fireChangeListener.ChangeEvent
, the event will be fired only when the user changes the text. -
getProgrammaticChangeEvents
public boolean getProgrammaticChangeEvents() -
getSelectionStart
public int getSelectionStart() -
getSelectionEnd
public int getSelectionEnd() -
getSelection
-
setSelection
public void setSelection(int selectionStart, int selectionEnd) Sets the selected text. -
selectAll
public void selectAll() -
clearSelection
public void clearSelection() -
setCursorPosition
public void setCursorPosition(int cursorPosition) Sets the cursor position and clears any selection. -
getCursorPosition
public int getCursorPosition() -
getOnscreenKeyboard
Default is an instance ofTextraField.DefaultOnscreenKeyboard
. -
setOnscreenKeyboard
-
setClipboard
public void setClipboard(com.badlogic.gdx.utils.Clipboard clipboard) -
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidth
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout
- Overrides:
getPrefWidth
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeight
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout
- Overrides:
getPrefHeight
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
setAlignment
public void setAlignment(int alignment) Sets text horizontal alignment (left, center or right).- See Also:
-
Align
-
getAlignment
public int getAlignment() -
positionChanged
protected void positionChanged()- Overrides:
positionChanged
in classcom.badlogic.gdx.scenes.scene2d.Actor
-
sizeChanged
protected void sizeChanged()- Overrides:
sizeChanged
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
act
public void act(float delta) - Overrides:
act
in classcom.badlogic.gdx.scenes.scene2d.Actor
-
setPasswordMode
public void setPasswordMode(boolean passwordMode) If true, the text in this text field will be shown as bullet characters.- See Also:
-
isPasswordMode
public boolean isPasswordMode() -
getPasswordCharacter
public char getPasswordCharacter()Gets the password character for the text field. Default is 8226 (the bullet char•
, Unicode 0x2022).- Returns:
- the current password character
-
setPasswordCharacter
public void setPasswordCharacter(char passwordCharacter) Sets the password character for the text field. If the character is not present in theFont
, this does nothing. Default is 8226 (the bullet char•
, Unicode 0x2022). -
getBlinkTime
public float getBlinkTime() -
setBlinkTime
public void setBlinkTime(float blinkTime) -
isCursorBlinking
public boolean isCursorBlinking() -
setCursorBlinking
public void setCursorBlinking(boolean blinkEnabled) -
setDisabled
public void setDisabled(boolean disabled) - Specified by:
setDisabled
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Disableable
-
isDisabled
public boolean isDisabled()- Specified by:
isDisabled
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Disableable
-
moveCursor
protected void moveCursor(boolean forward, boolean jump) -
continueCursor
protected boolean continueCursor(int index, int offset)
-