Class TypingLabel

java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.github.tommyettinger.textra.TextraLabel
com.github.tommyettinger.textra.TypingLabel
All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Layout

public class TypingLabel extends TextraLabel
An extension of Label that progressively shows the text as if it was being typed in real time, and allows the use of tokens in the following format: {TOKEN=PARAMETER}.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    com.badlogic.gdx.utils.FloatArray
     
    protected com.badlogic.gdx.utils.Array<com.github.tommyettinger.textra.TokenEntry>
     
    protected Layout
     

    Fields inherited from class com.github.tommyettinger.textra.TextraLabel

    align, font, layout, storedText, wrap
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    TypingLabel​(String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style)
     
    TypingLabel​(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin)
     
    TypingLabel​(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName)
     
    TypingLabel​(String text, Font font)
     
    TypingLabel​(String text, Font font, com.badlogic.gdx.graphics.Color color)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    act​(float delta)
     
    void
    Cancels calls to skipToTheEnd().
    void
    Removes all variables from this label.
    void
    draw​(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
    If your font uses Font.DistanceFieldType.SDF or Font.DistanceFieldType.MSDF, then this has to do some extra work to use the appropriate shader.
    com.badlogic.gdx.graphics.Color
    Returns a Color instance with the color to be used on CLEARCOLOR tokens.
    Returns the default token being used in this label.
    long
    getFromIntermediate​(int index)
     
    long
    getInLayout​(Layout layout, int index)
     
     
    Similar to Layout.toString(), but returns the original text with all the tokens unchanged.
    float
     
    float
     
    Returns the TypingListener associated with this label.
    com.badlogic.gdx.utils.ObjectMap<String,​String>
    Returns an ObjectMap with all the variable names and their respective replacement values.
    boolean
    Returns whether or not this label's char progression has ended.
    boolean
    Returns whether or not this label is paused.
    boolean
    Returns whether or not this label is currently skipping its typing progression all the way to the end.
    void
     
    void
    Parses all tokens of this label.
    void
    Pauses this label's character progression.
    boolean
     
    void
    Restarts this label with the original text and starts the char progression right away.
    void
    restart​(String newText)
    Restarts this label with the given text and starts the char progression right away.
    protected void
    Restores the original text with all tokens unchanged to this label.
    void
    Resumes this label's character progression.
    protected void
    Copies the content of getOriginalText() to the StringBuilder containing the original text with all tokens unchanged.
    void
    setDefaultToken​(String defaultToken)
    Sets the default token being used in this label.
    void
    setInLayout​(Layout layout, int index, long newGlyph)
     
    void
    setInLayouts​(int index, long newGlyph)
     
    void
    setIntermediateText​(CharSequence text, boolean modifyOriginalText, boolean restart)
     
    void
    setSize​(float width, float height)
     
    void
    setText​(String newText)
    Modifies the text of this label.
    protected void
    setText​(String newText, boolean modifyOriginalText)
    Sets the text of this label.
    protected void
    setText​(String newText, boolean modifyOriginalText, boolean restart)
    Sets the text of this label.
    void
    Sets the TypingListener associated with this label, or null to remove the current one.
    void
    setVariable​(String var, String value)
    Registers a variable and its respective replacement value to this label.
    void
    setVariables​(com.badlogic.gdx.utils.ObjectMap<String,​String> variableMap)
    Registers a set of variables and their respective replacement values to this label.
    void
    setVariables​(Map<String,​String> variableMap)
    Registers a set of variables and their respective replacement values to this label.
    void
    Skips the char progression to the end, showing the entire label.
    void
    skipToTheEnd​(boolean ignoreEvents)
    Skips the char progression to the end, showing the entire label.
    void
    skipToTheEnd​(boolean ignoreEvents, boolean ignoreEffects)
    Skips the char progression to the end, showing the entire label.
     

    Methods inherited from class com.github.tommyettinger.textra.TextraLabel

    getAlignment, isWrap, setAlignment, setWrap

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget

    getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, 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, positionChanged, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • tokenEntries

      protected final com.badlogic.gdx.utils.Array<com.github.tommyettinger.textra.TokenEntry> tokenEntries
    • workingLayout

      protected final Layout workingLayout
    • offsets

      public final com.badlogic.gdx.utils.FloatArray offsets
  • Constructor Details

    • TypingLabel

      public TypingLabel()
    • TypingLabel

      public TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin)
    • TypingLabel

      public TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName)
    • TypingLabel

      public TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style)
    • TypingLabel

      public TypingLabel(String text, Font font)
    • TypingLabel

      public TypingLabel(String text, Font font, com.badlogic.gdx.graphics.Color color)
  • Method Details

    • setText

      public void setText(String newText)
      Modifies the text of this label. If the char progression is already running, it's highly recommended to use restart(String) instead.
      Overrides:
      setText in class TextraLabel
      Parameters:
      newText - a String that can contain Font markup
    • setText

      protected void setText(String newText, boolean modifyOriginalText)
      Sets the text of this label.
      Parameters:
      modifyOriginalText - Flag determining if the original text should be modified as well. If false, only the display text is changed while the original text is untouched. If true, then this runs Parser.preprocess(CharSequence) on the text, which should only generally be run once per original text.
      See Also:
      restart(String)
    • setText

      protected void setText(String newText, boolean modifyOriginalText, boolean restart)
      Sets the text of this label.
      Parameters:
      modifyOriginalText - Flag determining if the original text should be modified as well. If false, only the display text is changed while the original text is untouched.
      restart - Whether or not this label should restart. Defaults to true.
      See Also:
      restart(String)
    • getOriginalText

      public StringBuilder getOriginalText()
      Similar to Layout.toString(), but returns the original text with all the tokens unchanged.
    • saveOriginalText

      protected void saveOriginalText(CharSequence text)
      Copies the content of getOriginalText() to the StringBuilder containing the original text with all tokens unchanged.
    • restoreOriginalText

      protected void restoreOriginalText()
      Restores the original text with all tokens unchanged to this label. Make sure to call parseTokens() to parse the tokens again.
    • getTypingListener

      public TypingListener getTypingListener()
      Returns the TypingListener associated with this label. May be null.
    • setTypingListener

      public void setTypingListener(TypingListener listener)
      Sets the TypingListener associated with this label, or null to remove the current one.
    • getClearColor

      public com.badlogic.gdx.graphics.Color getClearColor()
      Returns a Color instance with the color to be used on CLEARCOLOR tokens. Modify this instance to change the token color. Default value is specified by TypingConfig.
      See Also:
      TypingConfig.DEFAULT_CLEAR_COLOR
    • getDefaultToken

      public String getDefaultToken()
      Returns the default token being used in this label. Defaults to empty string.
    • setDefaultToken

      public void setDefaultToken(String defaultToken)
      Sets the default token being used in this label. This token will be used before the label's text, and after each {RESET} call. Useful if you want a certain token to be active at all times without having to type it all the time.
    • parseTokens

      public void parseTokens()
      Parses all tokens of this label. Use this after setting the text and any variables that should be replaced.
    • skipToTheEnd

      public void skipToTheEnd()
      Skips the char progression to the end, showing the entire label. Useful for when users don't want to wait for too long. Ignores all subsequent events by default.
    • skipToTheEnd

      public void skipToTheEnd(boolean ignoreEvents)
      Skips the char progression to the end, showing the entire label. Useful for when users don't want to wait for too long.
      Parameters:
      ignoreEvents - If true, skipped events won't be reported to the listener.
    • skipToTheEnd

      public void skipToTheEnd(boolean ignoreEvents, boolean ignoreEffects)
      Skips the char progression to the end, showing the entire label. Useful for when users don't want to wait for too long.
      Parameters:
      ignoreEvents - If true, skipped events won't be reported to the listener.
      ignoreEffects - If true, all text effects will be instantly cancelled.
    • cancelSkipping

      public void cancelSkipping()
      Cancels calls to skipToTheEnd(). Useful if you need to restore the label's normal behavior at some event after skipping.
    • isSkipping

      public boolean isSkipping()
      Returns whether or not this label is currently skipping its typing progression all the way to the end. This is only true if skipToTheEnd is called.
    • isPaused

      public boolean isPaused()
      Returns whether or not this label is paused.
    • pause

      public void pause()
      Pauses this label's character progression.
    • resume

      public void resume()
      Resumes this label's character progression.
    • hasEnded

      public boolean hasEnded()
      Returns whether or not this label's char progression has ended.
    • restart

      public void restart()
      Restarts this label with the original text and starts the char progression right away. All tokens are automatically parsed.
    • restart

      public void restart(String newText)
      Restarts this label with the given text and starts the char progression right away. All tokens are automatically parsed.
    • getVariables

      public com.badlogic.gdx.utils.ObjectMap<String,​String> getVariables()
      Returns an ObjectMap with all the variable names and their respective replacement values.
    • setVariable

      public void setVariable(String var, String value)
      Registers a variable and its respective replacement value to this label.
    • setVariables

      public void setVariables(com.badlogic.gdx.utils.ObjectMap<String,​String> variableMap)
      Registers a set of variables and their respective replacement values to this label.
    • setVariables

      public void setVariables(Map<String,​String> variableMap)
      Registers a set of variables and their respective replacement values to this label.
    • clearVariables

      public void clearVariables()
      Removes all variables from this label.
    • getPrefWidth

      public float getPrefWidth()
      Specified by:
      getPrefWidth in interface com.badlogic.gdx.scenes.scene2d.utils.Layout
      Overrides:
      getPrefWidth in class TextraLabel
    • getPrefHeight

      public float getPrefHeight()
      Specified by:
      getPrefHeight in interface com.badlogic.gdx.scenes.scene2d.utils.Layout
      Overrides:
      getPrefHeight in class TextraLabel
    • act

      public void act(float delta)
      Overrides:
      act in class com.badlogic.gdx.scenes.scene2d.Actor
    • remove

      public boolean remove()
      Overrides:
      remove in class com.badlogic.gdx.scenes.scene2d.Actor
    • setSize

      public void setSize(float width, float height)
      Overrides:
      setSize in class TextraLabel
    • layout

      public void layout()
      Specified by:
      layout in interface com.badlogic.gdx.scenes.scene2d.utils.Layout
      Overrides:
      layout in class TextraLabel
    • draw

      public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
      If your font uses Font.DistanceFieldType.SDF or Font.DistanceFieldType.MSDF, then this has to do some extra work to use the appropriate shader. If Font.enableShader(Batch) was called before rendering a group of TypingLabels, then they will try to share one Batch; otherwise this will change the shader to render SDF or MSDF, then change it back at the end of each draw() call.
      Overrides:
      draw in class TextraLabel
      Parameters:
      batch -
      parentAlpha -
    • toString

      public String toString()
      Overrides:
      toString in class com.badlogic.gdx.scenes.scene2d.Actor
    • setIntermediateText

      public void setIntermediateText(CharSequence text, boolean modifyOriginalText, boolean restart)
    • getIntermediateText

      public StringBuilder getIntermediateText()
    • getInLayout

      public long getInLayout(Layout layout, int index)
    • getFromIntermediate

      public long getFromIntermediate(int index)
    • setInLayout

      public void setInLayout(Layout layout, int index, long newGlyph)
    • setInLayouts

      public void setInLayouts(int index, long newGlyph)