Class EditBox

java.lang.Object
net.minecraft.client.gui.components.AbstractWidget
net.minecraft.client.gui.components.EditBox
All Implemented Interfaces:
GuiEventListener, Renderable, TabOrderedElement, LayoutElement, NarratableEntry, NarrationSupplier

public class EditBox extends AbstractWidget
  • Field Details

    • SPRITES

      private static final WidgetSprites SPRITES
    • BACKWARDS

      public static final int BACKWARDS
      See Also:
    • FORWARDS

      public static final int FORWARDS
      See Also:
    • CURSOR_INSERT_WIDTH

      private static final int CURSOR_INSERT_WIDTH
      See Also:
    • CURSOR_APPEND_CHARACTER

      private static final String CURSOR_APPEND_CHARACTER
      See Also:
    • DEFAULT_TEXT_COLOR

      public static final int DEFAULT_TEXT_COLOR
      See Also:
    • DEFAULT_HINT_STYLE

      public static final Style DEFAULT_HINT_STYLE
    • SEARCH_HINT_STYLE

      public static final Style SEARCH_HINT_STYLE
    • font

      private final Font font
    • value

      private String value
      Has the current text being edited on the textbox.
    • maxLength

      private int maxLength
    • bordered

      private boolean bordered
    • canLoseFocus

      private boolean canLoseFocus
      if true the textbox can lose focus by clicking elsewhere on the screen
    • isEditable

      private boolean isEditable
      If this value is true along with isFocused, keyTyped will process the keys.
    • centered

      private boolean centered
    • textShadow

      private boolean textShadow
    • invertHighlightedTextColor

      private boolean invertHighlightedTextColor
    • displayPos

      private int displayPos
      The current character index that should be used as start of the rendered text.
    • cursorPos

      private int cursorPos
    • highlightPos

      private int highlightPos
      other selection position, maybe the same as the cursor
    • textColor

      private int textColor
    • textColorUneditable

      private int textColorUneditable
    • suggestion

      private @Nullable String suggestion
    • responder

      private @Nullable Consumer<String> responder
    • formatters

      private final List<EditBox.TextFormatter> formatters
    • hint

      private @Nullable Component hint
    • focusedTime

      private long focusedTime
    • textX

      private int textX
    • textY

      private int textY
    • filter

      private Predicate<String> filter
      Called to check if the text is valid
  • Constructor Details

    • EditBox

      public EditBox(Font font, int width, int height, Component narration)
    • EditBox

      public EditBox(Font font, int x, int y, int width, int height, Component narration)
    • EditBox

      public EditBox(Font font, int x, int y, int width, int height, @Nullable EditBox oldBox, Component narration)
  • Method Details

    • setResponder

      public void setResponder(Consumer<String> responder)
    • addFormatter

      public void addFormatter(EditBox.TextFormatter formatter)
    • createNarrationMessage

      protected MutableComponent createNarrationMessage()
      Overrides:
      createNarrationMessage in class AbstractWidget
    • setValue

      public void setValue(String value)
      Sets the text of the textbox, and moves the cursor to the end.
    • getValue

      public String getValue()
    • getHighlighted

      public String getHighlighted()
    • setX

      public void setX(int x)
      Specified by:
      setX in interface LayoutElement
      Overrides:
      setX in class AbstractWidget
    • setY

      public void setY(int y)
      Specified by:
      setY in interface LayoutElement
      Overrides:
      setY in class AbstractWidget
    • setFilter

      public void setFilter(Predicate<String> filter)
      Sets a filter on the edit box that will only allow strings that pass the given predicate to be inserted.
    • insertText

      public void insertText(String input)
      Adds the given text after the cursor, or replaces the currently selected text if there is a selection.
    • onValueChange

      private void onValueChange(String value)
    • deleteText

      private void deleteText(int dir, boolean wholeWord)
    • deleteWords

      public void deleteWords(int dir)
      Deletes the given number of words from the current cursor's position, unless there is currently a selection, in which case the selection is deleted instead.
    • deleteChars

      public void deleteChars(int dir)
      Deletes the given number of characters from the current cursor's position, unless there is currently a selection, in which case the selection is deleted instead.
    • deleteCharsToPos

      public void deleteCharsToPos(int pos)
    • getWordPosition

      public int getWordPosition(int dir)
      Gets the starting index of the word at the specified number of words away from the cursor position.
    • getWordPosition

      private int getWordPosition(int dir, int from)
      Gets the starting index of the word at a distance of the specified number of words away from the given position.
    • getWordPosition

      private int getWordPosition(int dir, int from, boolean stripSpaces)
      Like getNthWordFromPos (which wraps this), but adds option for skipping consecutive spaces
    • moveCursor

      public void moveCursor(int dir, boolean hasShiftDown)
    • getCursorPos

      private int getCursorPos(int dir)
    • moveCursorTo

      public void moveCursorTo(int dir, boolean extendSelection)
    • setCursorPosition

      public void setCursorPosition(int pos)
    • moveCursorToStart

      public void moveCursorToStart(boolean hasShiftDown)
    • moveCursorToEnd

      public void moveCursorToEnd(boolean hasShiftDown)
    • keyPressed

      public boolean keyPressed(KeyEvent event)
    • canConsumeInput

      public boolean canConsumeInput()
    • charTyped

      public boolean charTyped(CharacterEvent event)
    • findClickedPositionInText

      private int findClickedPositionInText(MouseButtonEvent event)
    • selectWord

      private void selectWord(MouseButtonEvent event)
    • onClick

      public void onClick(MouseButtonEvent event, boolean doubleClick)
      Overrides:
      onClick in class AbstractWidget
    • onDrag

      protected void onDrag(MouseButtonEvent event, double dx, double dy)
      Overrides:
      onDrag in class AbstractWidget
    • playDownSound

      public void playDownSound(SoundManager soundManager)
      Overrides:
      playDownSound in class AbstractWidget
    • renderWidget

      public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float a)
      Specified by:
      renderWidget in class AbstractWidget
    • applyFormat

      private FormattedCharSequence applyFormat(String text, int offset)
    • updateTextPosition

      private void updateTextPosition()
    • setMaxLength

      public void setMaxLength(int maxLength)
      Sets the maximum length for the text in this text box. If the current text is longer than this length, the current text will be trimmed.
    • getMaxLength

      private int getMaxLength()
    • getCursorPosition

      public int getCursorPosition()
    • isBordered

      public boolean isBordered()
    • setBordered

      public void setBordered(boolean bordered)
      Sets whether the background and outline of this text box should be drawn.
    • setTextColor

      public void setTextColor(int textColor)
      Sets the color to use when drawing this text box's text. A different color is used if this text box is disabled.
    • setTextColorUneditable

      public void setTextColorUneditable(int textColorUneditable)
      Sets the color to use for text in this text box when this text box is disabled.
    • setFocused

      public void setFocused(boolean focused)
      Description copied from interface: GuiEventListener
      Sets the focus state of the GUI element.
      Specified by:
      setFocused in interface GuiEventListener
      Overrides:
      setFocused in class AbstractWidget
      Parameters:
      focused - true to apply focus, false to remove focus
    • isEditable

      private boolean isEditable()
    • setEditable

      public void setEditable(boolean isEditable)
      Sets whether this text box is enabled. Disabled text boxes cannot be typed in.
    • isCentered

      private boolean isCentered()
    • setCentered

      public void setCentered(boolean centered)
    • setTextShadow

      public void setTextShadow(boolean textShadow)
    • setInvertHighlightedTextColor

      public void setInvertHighlightedTextColor(boolean invertHighlightedTextColor)
    • getInnerWidth

      public int getInnerWidth()
    • setHighlightPos

      public void setHighlightPos(int pos)
      Sets the position of the selection anchor (the selection anchor and the cursor position mark the edges of the selection). If the anchor is set beyond the bounds of the current text, it will be put back inside.
    • scrollTo

      private void scrollTo(int pos)
    • setCanLoseFocus

      public void setCanLoseFocus(boolean canLoseFocus)
      Sets whether this text box loses focus when something other than it is clicked.
    • isVisible

      public boolean isVisible()
    • setVisible

      public void setVisible(boolean visible)
      Sets whether this textbox is visible.
    • setSuggestion

      public void setSuggestion(@Nullable String suggestion)
    • getScreenX

      public int getScreenX(int charIndex)
    • updateWidgetNarration

      public void updateWidgetNarration(NarrationElementOutput output)
      Specified by:
      updateWidgetNarration in class AbstractWidget
    • setHint

      public void setHint(Component hint)
    • getTextShadow

      public boolean getTextShadow()