Package arc.scene.ui

Class TextField

java.lang.Object
arc.scene.Element
arc.scene.ui.TextField
All Implemented Interfaces:
Disableable
Direct Known Subclasses:
TextArea

public class TextField extends Element implements Disableable
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.

  • 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

      public Object imeData
      Special field containing implementation-specific data for IME support.
    • layout

      protected final GlyphLayout layout
    • glyphPositions

      protected final FloatSeq glyphPositions
    • text

      protected String text
    • cursor

      protected int cursor
    • selectionStart

      protected int selectionStart
    • hasSelection

      protected boolean hasSelection
    • writeEnters

      protected boolean writeEnters
    • displayText

      protected CharSequence displayText
    • fontOffset

      protected float fontOffset
    • textHeight

      protected float textHeight
    • textOffset

      protected float textOffset
    • inputDialogListener

      protected InputListener inputDialogListener
    • style

      protected TextField.TextFieldStyle style
    • inputListener

      protected InputListener inputListener
    • listener

      protected TextField.TextFieldListener listener
    • validator

      protected TextField.TextFieldValidator validator
    • filter

      protected TextField.TextFieldFilter filter
    • focusTraversal

      protected boolean focusTraversal
    • onlyFontChars

      protected boolean onlyFontChars
    • disabled

      protected boolean disabled
    • undoText

      protected String undoText
    • lastChangeTime

      protected long lastChangeTime
    • passwordMode

      protected boolean passwordMode
    • renderOffset

      protected float renderOffset
    • cursorOn

      protected boolean cursorOn
    • hasInputDialog

      protected boolean hasInputDialog
    • keyRepeatTask

      protected arc.scene.ui.TextField.KeyRepeatTask keyRepeatTask
    • programmaticChangeEvents

      protected boolean programmaticChangeEvents
    • messageText

      protected String messageText
    • textHAlign

      protected int textHAlign
    • selectionX

      protected float selectionX
    • selectionWidth

      protected float selectionWidth
    • passwordBuffer

      protected StringBuilder passwordBuffer
    • passwordCharacter

      protected char passwordCharacter
    • visibleTextStart

      protected int visibleTextStart
    • visibleTextEnd

      protected int visibleTextEnd
    • maxLength

      protected int maxLength
    • blinkTime

      protected float blinkTime
  • Constructor Details

  • Method Details

    • initialize

      protected void initialize()
    • createInputListener

      protected InputListener 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 by setText(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

      public TextField.TextFieldStyle getStyle()
      Returns the text field's style. Modifying the returned style may not have an effect until setStyle(TextFieldStyle) is called.
    • setStyle

      public void setStyle(TextField.TextFieldStyle style)
    • calculateOffsets

      protected void calculateOffsets()
    • draw

      public void draw()
      Description copied from class: Element
      Draws the element. Does nothing by default.
      Overrides:
      draw in class Element
    • isValid

      public boolean isValid()
    • getTextY

      protected float getTextY(Font font, Drawable background)
    • drawSelection

      protected void drawSelection(Drawable selection, Font font, float x, float y)
      Draws selection rectangle
    • drawText

      protected void drawText(Font font, float x, float y)
    • drawCursor

      protected void drawCursor(Drawable cursorPatch, Font font, float x, float y)
    • 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

      public void paste(String content, boolean fireChangeEvent)
    • 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

      public InputListener getDefaultInputListener()
    • setTextFieldListener

      public void setTextFieldListener(TextField.TextFieldListener listener)
      Parameters:
      listener - May be null.
    • typed

      public void typed(char ch, Runnable run)
    • typed

      public void typed(Cons<Character> cons)
    • getFilter

      public TextField.TextFieldFilter getFilter()
    • setFilter

      public void setFilter(TextField.TextFieldFilter filter)
      Parameters:
      filter - May be null.
    • setValidator

      public void setValidator(TextField.TextFieldValidator validator)
    • getValidator

      public TextField.TextFieldValidator getValidator()
    • setFocusTraversal

      public void setFocusTraversal(boolean focusTraversal)
      If true (the default), tab/shift+tab will move to the next text field.
    • getMessageText

      public String getMessageText()
      Returns:
      May be null.
    • setMessageText

      public void setMessageText(String messageText)
      Sets the text that will be drawn in the text field if no text has been entered.
      Parameters:
      messageText - may be null.
    • appendText

      public void appendText(String str)
      Parameters:
      str - If null, "" is used.
    • getText

      public String getText()
      Returns:
      Never null, might be an empty string.
    • setText

      public void setText(String str)
      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 fire ChangeListener.ChangeEvent, the event will be fired only when user changes the text.
    • getSelectionStart

      public int getSelectionStart()
    • getSelection

      public String 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 class Element
    • getPrefHeight

      public float getPrefHeight()
      Overrides:
      getPrefHeight in class Element
    • 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 the Font. Default is 149 (bullet).
    • setBlinkTime

      public void setBlinkTime(float blinkTime)
    • isDisabled

      public boolean isDisabled()
      Specified by:
      isDisabled in interface Disableable
    • setDisabled

      public void setDisabled(boolean disabled)
      Specified by:
      setDisabled in interface Disableable
    • moveCursor

      protected void moveCursor(boolean forward, boolean jump)
    • continueCursor

      protected boolean continueCursor(int index, int offset)