Class TextInputWidget

java.lang.Object
net.minecraft.client.gui.widget.ClickableWidget
net.uku3lig.ukulib.config.option.widget.TextInputWidget
All Implemented Interfaces:
net.minecraft.client.gui.Drawable, net.minecraft.client.gui.Element, net.minecraft.client.gui.Narratable, net.minecraft.client.gui.navigation.Navigable, net.minecraft.client.gui.Selectable, net.minecraft.client.gui.widget.Widget, CheckedOption
Direct Known Subclasses:
ColorInputWidget

public class TextInputWidget extends net.minecraft.client.gui.widget.ClickableWidget implements net.minecraft.client.gui.Drawable, CheckedOption
A widget to input text. Based on TextFieldWidget.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.minecraft.client.gui.Selectable

    net.minecraft.client.gui.Selectable.SelectionType
  • Field Summary

    Fields inherited from class net.minecraft.client.gui.widget.ClickableWidget

    active, alpha, height, hovered, visible, width

    Fields inherited from interface net.minecraft.client.gui.Element

    MAX_DOUBLE_CLICK_INTERVAL
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextInputWidget(int x, int y, int width, int height, String initialValue, Consumer<String> changedListener, String suggestion, Predicate<String> textPredicate, int maxLength)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    appendClickableNarrations(net.minecraft.client.gui.screen.narration.NarrationMessageBuilder builder)
     
    boolean
    charTyped(char chr, int modifiers)
     
    void
    eraseCharacters(int characterOffset)
    Erases characters depending on the characterOffset.
    void
    eraseWords(int wordOffset)
    Erases words depending on the wordOffset.
    int
    Returns the position of the cursor, or the beginning of the selection.
    int
    Returns width of the text field, without the border.
    int
    The maximum length of the text.
    protected net.minecraft.text.MutableText
     
    @Nullable net.minecraft.client.gui.navigation.GuiNavigationPath
    getNavigationPath(net.minecraft.client.gui.navigation.GuiNavigation navigation)
     
    Gets the currently selected text, if any.
    The text.
    int
    getWordSkipPosition(int wordOffset)
    Gets the position of the word to skip to.
    boolean
    Checks if the text field is inactive.
    boolean
    isMouseOver(double mouseX, double mouseY)
     
    boolean
    Checks if the option is valid.
    boolean
    Whether the text field is currently visible.
    boolean
    keyPressed(int keyCode, int scanCode, int modifiers)
     
    boolean
    mouseClicked(double mouseX, double mouseY, int button)
     
    void
    moveCursor(int offset)
    Moves the cursor by the specified offset.
    void
    renderButton(net.minecraft.client.gui.DrawContext drawContext, int mouseX, int mouseY, float delta)
     
    void
    setCursor(int cursor)
    Sets the cursor position.
    void
    Sets the cursor position to the end of the text.
    void
    Sets the cursor position to the start of the text.
    void
    setSelectionEnd(int index)
    Sets the end of the selection.
    void
    setSelectionStart(int cursor)
    Sets the start of the selection.
    void
    Sets the text.
    void
    write(String text)
    Writes the given text to the current cursor position.

    Methods inherited from class net.minecraft.client.gui.widget.ClickableWidget

    appendDefaultNarrations, appendNarrations, clicked, drawScrollableText, drawScrollableText, drawScrollableText, forEachChild, getHeight, getMessage, getNarrationMessage, getNavigationFocus, getNavigationOrder, getTooltip, getTooltipPositioner, getType, getWidth, getX, getY, isFocused, isHovered, isNarratable, isSelected, isValidClickButton, mouseDragged, mouseReleased, onClick, onDrag, onRelease, playDownSound, render, setAlpha, setFocused, setHeight, setMessage, setNavigationOrder, setTooltip, setTooltipDelay, setWidth, setX, setY

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.minecraft.client.gui.Drawable

    render

    Methods inherited from interface net.minecraft.client.gui.Element

    getFocusedPath, keyReleased, mouseMoved, mouseScrolled

    Methods inherited from interface net.minecraft.client.gui.widget.Widget

    setPosition
  • Constructor Details

    • TextInputWidget

      public TextInputWidget(int x, int y, int width, int height, String initialValue, Consumer<String> changedListener, String suggestion, Predicate<String> textPredicate, int maxLength)
      Constructor.
      Parameters:
      x - the x position
      y - the y position
      width - the width
      height - the height
      initialValue - the initial value
      changedListener - the callback to set the value
      suggestion - the suggestion
      textPredicate - the predicate to check the text
      maxLength - the maximum length of the text
  • Method Details

    • getNarrationMessage

      protected net.minecraft.text.MutableText getNarrationMessage()
      Overrides:
      getNarrationMessage in class net.minecraft.client.gui.widget.ClickableWidget
    • setText

      public void setText(String text)
      Sets the text.
      Parameters:
      text - the new text
    • getSelectedText

      public String getSelectedText()
      Gets the currently selected text, if any.
      Returns:
      the selected text
    • write

      public void write(String text)
      Writes the given text to the current cursor position.
      Parameters:
      text - the text to write
    • eraseWords

      public void eraseWords(int wordOffset)
      Erases words depending on the wordOffset.
      Parameters:
      wordOffset - the offset
    • eraseCharacters

      public void eraseCharacters(int characterOffset)
      Erases characters depending on the characterOffset.
      Parameters:
      characterOffset - the offset
    • getWordSkipPosition

      public int getWordSkipPosition(int wordOffset)
      Gets the position of the word to skip to. Used for deleting words.
      Parameters:
      wordOffset - the offset
      Returns:
      the position of the word to skip to
      See Also:
      • getWordSkipPosition(int, int)
    • moveCursor

      public void moveCursor(int offset)
      Moves the cursor by the specified offset.
      Parameters:
      offset - the offset
    • setCursor

      public void setCursor(int cursor)
      Sets the cursor position.
      Parameters:
      cursor - the cursor position
    • setSelectionStart

      public void setSelectionStart(int cursor)
      Sets the start of the selection.
      Parameters:
      cursor - the start of the selection
    • setCursorToStart

      public void setCursorToStart()
      Sets the cursor position to the start of the text.
    • setCursorToEnd

      public void setCursorToEnd()
      Sets the cursor position to the end of the text.
    • keyPressed

      public boolean keyPressed(int keyCode, int scanCode, int modifiers)
      Specified by:
      keyPressed in interface net.minecraft.client.gui.Element
    • isInactive

      public boolean isInactive()
      Checks if the text field is inactive.
      Returns:
      true if the text field is inactive, false otherwise
    • charTyped

      public boolean charTyped(char chr, int modifiers)
      Specified by:
      charTyped in interface net.minecraft.client.gui.Element
    • mouseClicked

      public boolean mouseClicked(double mouseX, double mouseY, int button)
      Specified by:
      mouseClicked in interface net.minecraft.client.gui.Element
      Overrides:
      mouseClicked in class net.minecraft.client.gui.widget.ClickableWidget
    • renderButton

      public void renderButton(net.minecraft.client.gui.DrawContext drawContext, int mouseX, int mouseY, float delta)
      Specified by:
      renderButton in class net.minecraft.client.gui.widget.ClickableWidget
    • getCursor

      public int getCursor()
      Returns the position of the cursor, or the beginning of the selection.
      Returns:
      the cursor position
    • getNavigationPath

      @Nullable public @Nullable net.minecraft.client.gui.navigation.GuiNavigationPath getNavigationPath(net.minecraft.client.gui.navigation.GuiNavigation navigation)
      Specified by:
      getNavigationPath in interface net.minecraft.client.gui.Element
      Overrides:
      getNavigationPath in class net.minecraft.client.gui.widget.ClickableWidget
    • isMouseOver

      public boolean isMouseOver(double mouseX, double mouseY)
      Specified by:
      isMouseOver in interface net.minecraft.client.gui.Element
      Overrides:
      isMouseOver in class net.minecraft.client.gui.widget.ClickableWidget
    • getInnerWidth

      public int getInnerWidth()
      Returns width of the text field, without the border.
      Returns:
      the inner width
    • setSelectionEnd

      public void setSelectionEnd(int index)
      Sets the end of the selection.
      Parameters:
      index - the end of the selection
    • isVisible

      public boolean isVisible()
      Whether the text field is currently visible.
      Returns:
      true if the text field is visible, false otherwise
    • appendClickableNarrations

      public void appendClickableNarrations(net.minecraft.client.gui.screen.narration.NarrationMessageBuilder builder)
      Specified by:
      appendClickableNarrations in class net.minecraft.client.gui.widget.ClickableWidget
    • isValid

      public boolean isValid()
      Description copied from interface: CheckedOption
      Checks if the option is valid.
      Specified by:
      isValid in interface CheckedOption
      Returns:
      true if the option is valid, false otherwise
    • getText

      public String getText()
      The text.
      Returns:
      the text
    • getMaxLength

      public int getMaxLength()
      The maximum length of the text.
      Returns:
      the maximum length of the text