Package com.github.tommyettinger.textra
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
An extension of
This is meant to work with
TextraLabel that progressively shows the text as if it was being typed in real time, and
allows the use of tokens in the format: {TOKEN=PARAMETER;ANOTHER_PARAMETER;MORE}. These tokens can
add various effects to spans of text, such as the token WIND making text flutter and flap around, or
BLINK making it flash an alternate color repeatedly. These work in addition to the tags permitted by
TextraLabel, such as [light blue] for to change text color, or [_] to underline text.
For compatibility with other systems that may already use curly braces, such as some I18N techniques, you can use
[- instead of { and ] instead of } to use tokens without writing
out curly braces.
This is meant to work with
FWSkin or one of its subclasses, such as FreeTypistSkin, and isn't
guaranteed to work with a regular Skin. FWSkin can load the same JSON files Skin uses, and it extends Skin.
If you encounter an unusually high amount of native memory being used, the cause is most likely Font objects being
created from BitmapFont objects repeatedly, which FWSkin is designed to avoid. When using any scene2d.ui
widget from TextraTypist with an FWSkin, the correct and optimal style from Styles is used, and that avoids
creating more and more Font objects as widgets are created and destroyed. Subclasses of FWSkin are also perfectly
fine to use, such as the subclass in FreeTypist that allows
using FreeType to generate a Font from skin JSON configuration.
Using a regular libGDX Skin object, not an FWSkin, will be a problem.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Justifyprotected booleanintThe global glyph index (as used bysetInWorkingLayout(int, long)) of the last glyph touched by the user.intThe global glyph index (as used bysetInWorkingLayout(int, long)) of the last glyph hovered or dragged over by the user (including a click and mouse movement without a click).booleanIf true, this label will allow clicking and dragging to select a range of text, iftrackingInputis also true.com.badlogic.gdx.scenes.scene2d.utils.DrawableintThe inclusive end index for the selected text, if there is a selection.intThe inclusive start index for the selected text, if there is a selection.booleanIf true, this will attempt to track which glyph the user's mouse or other pointer is over (seeoverIndexandlastTouchedIndex).protected final LayoutFields inherited from class com.github.tommyettinger.textra.TextraLabel
align, font, layout, prefSizeInvalid, storedText, style, wrapFields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
POOLS -
Constructor Summary
ConstructorsConstructorDescriptionCreates a TypingLabel that uses the libGDX default font (lsans-15) and starts with no text.TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin) The skin should almost certainly be anFWSkinor one of its subclasses.TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, Font replacementFont) The skin should almost certainly be anFWSkinor one of its subclasses.TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName) The skin should almost certainly be anFWSkinor one of its subclasses.TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName, Font replacementFont) The skin should almost certainly be anFWSkinor one of its subclasses.TypingLabel(String text, Font font) Creates a TypingLabel with the given markup text and Font, without needing a skin.TypingLabel(String text, Font font, com.badlogic.gdx.graphics.Color color) Creates a TypingLabel with the given markup text, Font, and font color, without needing a skin.TypingLabel(String text, Styles.LabelStyle style) Creates a TypingLabel with the given markup text and style, without needing a skin.TypingLabel(String text, Styles.LabelStyle style, Font replacementFont) Creates a TypingLabel with the given markup text, style, and Font, without needing a skin. -
Method Summary
Modifier and TypeMethodDescriptionvoidact(float delta) voidappendText(CharSequence newText) Continues this label's typing effect after it has previously ended, appending the given text and starting the char progression (again) right away.voidCancels calls toskipToTheEnd().voidRemoves all variables from this label.booleanIf this label isselectableand there is a selected range of text, this copies that range of text to the clipboard and returns true; otherwise, it returns false.voiddraw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) If your font usesFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, then this has to do some extra work to use the appropriate shader.voiddrawSection(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha, int startIndex, int endIndex) Renders a subsection of the glyphs in this label.com.badlogic.gdx.utils.FloatArrayContains one float per glyph; each is a multiplier that affects the x-advance of that glyph.com.badlogic.gdx.graphics.ColorReturns aColorinstance with the color to be used onCLEARCOLORtokens.floatgetCumulativeLineHeight(int index) Gets the height of the Line containing the glyph at the given index, plus the heights of all preceding lines, in the working layout.Returns the default token being used in this label.Gets the ellipsis, which may be null, or may be a String that can be placed at the end of the text if its max lines are exceeded.longgetFromIntermediate(int index) longgetInLayout(Layout layout, int index) longgetInWorkingLayout(int index) floatgetLineHeight(int index) Gets the height of the Line containing the glyph at the given index, in the working layout.getLineInLayout(Layout layout, int index) intThe maximum number ofLines this label can display.com.badlogic.gdx.utils.FloatArrayContains two floats per glyph; even items are x offsets, odd items are y offsets.Similar toLayout.toString(), but returns the original text with all the tokens unchanged.floatfloatcom.badlogic.gdx.utils.FloatArrayContains one float per glyph; each is a rotation in degrees to apply to that glyph (around its center).If this label isselectableand there is a selected range of text, this returns that range of text; otherwise, it returns the empty string.com.badlogic.gdx.utils.FloatArrayContains two floats per glyph, as size multipliers; even items apply to x, odd items apply to y.floatReturns theTypingListenerassociated with this label.Returns theObjectMapwith all the variable names and their respective replacement values that this label uses to handle{VAR=NAME}replacements.Returns the meant-for-internal-use-only Layout that is frequently changed as this label is displayed.booleanhasEnded()Returns whether this label's char progression has ended.booleanIf this label isselectableand there is a selected range of text, this returns true; otherwise, it returns false.voidinsertInLayout(Layout layout, int index, long newGlyph) voidinsertInLayout(Layout layout, int index, CharSequence text) booleanisPaused()Returns whether this label is paused.booleanReturns true if and only ifselectableis true andtrackingInputis true; otherwise false.booleanReturns whether this label is currently skipping its typing progression all the way to the end.voidlayout()intlength()Gets the length in glyphs of the working layout (what is displayed).voidParses all tokens of this label.voidpause()Pauses this label's character progression.voidremoveVariable(String var) Removes a variable and its respective replacement value from this label's variable map.voidrestart()Restarts this label with the original text and starts the char progression right away.voidrestart(CharSequence newText) Restarts this label with the given text and starts the char progression right away.protected voidRestores the original text with all tokens unchanged to this label.voidresume()Resumes this label's character progression.protected voidsaveOriginalText(CharSequence text) Copies the content ofgetOriginalText()to theStringBuildercontaining the original text with all tokens unchanged.voidsetDefaultToken(String defaultToken) Sets the default token being used in this label.voidsetEllipsis(String ellipsis) Sets the ellipsis text, which replaces the last few glyphs if non-null and the text added would exceed thegetMaxLines()of this label's working layout.voidsetInLayout(Layout layout, int index, long newGlyph) voidsetIntermediateText(CharSequence text, boolean modifyOriginalText, boolean restart) voidsetInWorkingLayout(int index, long newGlyph) voidsetMaxLines(int maxLines) Sets the maximum number ofLines this Layout can display; this is always at least 1.setSelectable(boolean selectable) voidsetSize(float width, float height) voidModifies the text of this label.voidSets the text of this label.voidSets the text of this label.voidsetTextSpeed(float textSpeed) voidsetTypingListener(TypingListener listener) Sets theTypingListenerassociated with this label, ornullto remove the current one.voidsetVariable(String var, String value) Registers a variable and its respective replacement value to this label.voidsetVariables(com.badlogic.gdx.utils.ObjectMap<String, String> variableMap) Registers a set of variables and their respective replacement values to this label.voidsetVariables(Map<String, String> variableMap) Registers a set of variables and their respective replacement values to this label.Skips the char progression to the end, showing the entire label.skipToTheEnd(boolean ignoreEvents) Skips the char progression to the end, showing the entire label.skipToTheEnd(boolean ignoreEvents, boolean ignoreEffects) Skips the char progression to the end, showing the entire label.substring(int start, int end) Gets a String from the working layout of this label, made of only the char portions of the glyphs from start (inclusive) to end (exclusive).toString()voidtriggerEvent(String event, boolean always) Triggers an event with the given String name.Methods inherited from class com.github.tommyettinger.textra.TextraLabel
getAlignment, getFont, getGlyph, invalidate, isWrap, setAlignment, setFont, setFont, setHeight, setParent, setStage, setSuperHeight, setSuperWidth, setWidth, setWrap, useIntegerPositions, validateMethods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChangedMethods 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, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setName, setOrigin, setOrigin, setOriginX, setOriginY, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setTouchable, setUserObject, setVisible, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
Field Details
-
workingLayout
-
defaultJustify
-
trackingInput
public boolean trackingInputIf true, this will attempt to track which glyph the user's mouse or other pointer is over (seeoverIndexandlastTouchedIndex). -
selectable
public boolean selectableIf true, this label will allow clicking and dragging to select a range of text, iftrackingInputis also true. This does not allow the text to be edited unless so implemented by another class. If text can be selected, then you can usegetSelectedText()to get the selected String, orcopySelectedText()to copy that text directly. To copy automatically, use a listener that checksTypingListener.event(String), and when the event String is"*SELECTED", that means a click-and-drag selected a range of text in this label, and you can do what you want with the selected text (such as callcopySelectedText()). -
selectionDrawable
public com.badlogic.gdx.scenes.scene2d.utils.Drawable selectionDrawable -
lastTouchedIndex
public int lastTouchedIndexThe global glyph index (as used bysetInWorkingLayout(int, long)) of the last glyph touched by the user. If nothing in this TypingLabel was touched during the last call todraw(Batch, float), then this will be either -1 (if the last touch was, roughly, before the first glyph) or -2 (if the last touch was after the last glyph). This only changes when a click, tap, or other touch was just issued. -
overIndex
public int overIndexThe global glyph index (as used bysetInWorkingLayout(int, long)) of the last glyph hovered or dragged over by the user (including a click and mouse movement without a click). If nothing in this TypingLabel was moved over during the last call todraw(Batch, float), then this will be -1 . This changes whenever the mouse or a pointer is over a glyph in this. -
selectionStart
public int selectionStartThe inclusive start index for the selected text, if there is a selection. This should be -1 if there is no selection, or sometimes -2 if the selection went past the end of the text. This is essentially interchangeable withselectionEnd; as long as they are different, it doesn't matter which is higher or lower. -
selectionEnd
public int selectionEndThe inclusive end index for the selected text, if there is a selection. This should be -1 if there is no selection, or sometimes -2 if the selection went past the end of the text. This is essentially interchangeable withselectionStart; as long as they are different, it doesn't matter which is higher or lower. -
dragging
protected boolean dragging -
activeEffects
-
-
Constructor Details
-
TypingLabel
public TypingLabel()Creates a TypingLabel that uses the libGDX default font (lsans-15) and starts with no text. The default font will not look very good when scaled, so this should usually stay its default font size. This allocates a new Font every time it is called, so you should avoid this constructor in code that is called more than a handful of times. Its only valid use is in debugging. -
TypingLabel
The skin should almost certainly be anFWSkinor one of its subclasses. Do not use scene2d.ui'sSkinunless you are prepared to dispose of Fonts manually, without any help.- Parameters:
text- markup text that can contain square-bracket tags and curly-brace tokensskin- almost always anFWSkinor one of its subclasses; must have aStyles.LabelStyleorLabel.LabelStyleregistered as "default"
-
TypingLabel
The skin should almost certainly be anFWSkinor one of its subclasses. Do not use scene2d.ui'sSkinunless you are prepared to dispose of Fonts manually, without any help.- Parameters:
text- markup text that can contain square-bracket tags and curly-brace tokensskin- almost always anFWSkinor one of its subclasses; must have aStyles.LabelStyleorLabel.LabelStyleregistered as "default"replacementFont- will be used instead of the Font loaded from skin
-
TypingLabel
The skin should almost certainly be anFWSkinor one of its subclasses. Do not use scene2d.ui'sSkinunless you are prepared to dispose of Fonts manually, without any help.- Parameters:
text- markup text that can contain square-bracket tags and curly-brace tokensskin- almost always anFWSkinor one of its subclasses; must have aStyles.LabelStyleorLabel.LabelStyleregistered with the given styleNamestyleName- the name of theStyles.LabelStyleto load from skin
-
TypingLabel
public TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName, Font replacementFont) The skin should almost certainly be anFWSkinor one of its subclasses. Do not use scene2d.ui'sSkinunless you are prepared to dispose of Fonts manually, without any help.- Parameters:
text- markup text that can contain square-bracket tags and curly-brace tokensskin- almost always anFWSkinor one of its subclasses; must have aStyles.LabelStyleorLabel.LabelStyleregistered with the given styleNamestyleName- the name of theStyles.LabelStyleto load from skinreplacementFont- will be used instead of the Font loaded from skin
-
TypingLabel
Creates a TypingLabel with the given markup text and style, without needing a skin. Note that you can obtain widget styles inStyleseither by manually constructing the appropriate style, or by loading a skin JSON file withFWSkinor one of its subclasses.- Parameters:
text- markup text that can contain square-bracket tags and curly-brace tokensstyle- a style fromStylesand not from scene2d.ui; often made manually
-
TypingLabel
Creates a TypingLabel with the given markup text, style, and Font, without needing a skin. Note that you can obtain widget styles inStyleseither by manually constructing the appropriate style, or by loading a skin JSON file withFWSkinor one of its subclasses.- Parameters:
text- markup text that can contain square-bracket tags and curly-brace tokensstyle- a style fromStylesand not from scene2d.ui; often made manuallyreplacementFont- will be used instead of the Font from the style
-
TypingLabel
Creates a TypingLabel with the given markup text and Font, without needing a skin.- Parameters:
text- markup text that can contain square-bracket tags and curly-brace tokensfont- will be used for all text
-
TypingLabel
Creates a TypingLabel with the given markup text, Font, and font color, without needing a skin.- Parameters:
text- markup text that can contain square-bracket tags and curly-brace tokensfont- will be used for all textcolor- the default foreground color for text
-
-
Method Details
-
setText
Modifies the text of this label. If the char progression is already running, it's highly recommended to userestart(CharSequence)instead.- Overrides:
setTextin classTextraLabel- Parameters:
newText- what to use as the new text (and original text) of this label
-
setText
Sets the text of this label. If the char progression is already running, it's highly recommended to userestart(CharSequence)instead. This overload allows specifying if the original text, which is used when parsing the tokens (withparseTokens()), should be changed to match the given text. IfmodifyOriginalTextis true, this willpreprocessthe text, which should generally be run once per original text and no more.
This overload callssetText(String, boolean, boolean)withrestartset to false.- Parameters:
modifyOriginalText- Flag determining if the original text should be modified as well. Iffalse, only the display text is changed while the original text is untouched. Iftrue, then this runsParser.preprocess(String)on the text, which should only generally be run once per original text.- See Also:
-
setText
Sets the text of this label. If the char progression is already running, it's highly recommended to userestart(CharSequence)instead. This overload allows specifying if the original text, which is used when parsing the tokens (withparseTokens()), should be changed to match the given text. This will not ever callParser.preprocess(String), which makes it different fromsetText(String, boolean). You can also specify whether the text animation should restart or not here.- Parameters:
modifyOriginalText- Flag determining if the original text should be modified as well. Iffalse, only the display text is changed while the original text is untouched.restart- Whether this label should restart. Defaults to true.- See Also:
-
getOriginalText
Similar toLayout.toString(), but returns the original text with all the tokens unchanged. -
saveOriginalText
Copies the content ofgetOriginalText()to theStringBuildercontaining 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 callparseTokens()to parse the tokens again. -
getTypingListener
Returns theTypingListenerassociated with this label. May benull. -
setTypingListener
Sets theTypingListenerassociated with this label, ornullto remove the current one. -
getClearColor
public com.badlogic.gdx.graphics.Color getClearColor()Returns aColorinstance with the color to be used onCLEARCOLORtokens. Modify this instance to change the token color. Default value is specified byTypingConfig.- See Also:
-
getDefaultToken
Returns the default token being used in this label. Defaults to empty string. -
setDefaultToken
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
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. Doesn't change running effects. This callsact(float)with a delta ofFloat.MIN_VALUE, which allows the text to be skipped ahead without noticeably changing anything time-based.- Overrides:
skipToTheEndin classTextraLabel- Returns:
- this, for chaining
-
skipToTheEnd
Skips the char progression to the end, showing the entire label. Useful for when users don't want to wait for too long. This doesn't change running effects. This callsact(float)with a delta ofFloat.MIN_VALUE, which allows the text to be skipped ahead without noticeably changing anything time-based.- Parameters:
ignoreEvents- Iftrue, skipped events won't be reported to the listener.- Returns:
- this, for chaining
-
skipToTheEnd
Skips the char progression to the end, showing the entire label. Useful for when users don't want to wait for too long. This callsact(float)with a delta ofFloat.MIN_VALUE, which allows the text to be skipped ahead without noticeably changing anything time-based.- Parameters:
ignoreEvents- Iftrue, skipped events won't be reported to the listener.ignoreEffects- Iftrue, all text effects will be instantly cancelled.- Returns:
- this, for chaining
-
cancelSkipping
public void cancelSkipping()Cancels calls toskipToTheEnd(). Useful if you need to restore the label's normal behavior at some event after skipping. -
isSkipping
public boolean isSkipping()Returns whether 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 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 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
Restarts this label with the given text and starts the char progression right away. All tokens are automatically parsed. If you are reusing an existing TypingLabel and its size will change once it holdsnewText, you may need to calllabel.setSize(0, 0);before calling this. This does not change its size by itself, because restarting is also performed internally and changing the size internally could cause unexpected (read: very buggy) behavior for code using this library.- Parameters:
newText- the String, StringBuilder, or other CharSequence that this TypingLabel will start displaying
-
appendText
Continues this label's typing effect after it has previously ended, appending the given text and starting the char progression (again) right away. All tokens are automatically parsed. If this TypingLabel has not yet ended when this is called, then this callsskipToTheEnd(false, false).- Parameters:
newText- a String, StringBuilder, or other CharSequence that will be appended to the finished text
-
getVariables
Returns theObjectMapwith all the variable names and their respective replacement values that this label uses to handle{VAR=NAME}replacements. This returns the map directly. -
setVariable
Registers a variable and its respective replacement value to this label.- Parameters:
var- the String name to use for a variablevalue- the String value to use as a replacement
-
removeVariable
Removes a variable and its respective replacement value from this label's variable map.- Parameters:
var- the String name of a variable to remove
-
setVariables
Registers a set of variables and their respective replacement values to this label.- Parameters:
variableMap- an ObjectMap of variable names to their replacement Strings
-
setVariables
Registers a set of variables and their respective replacement values to this label.- Parameters:
variableMap- a Map of variable names to their replacement Strings; null keys will be ignored silently
-
clearVariables
public void clearVariables()Removes all variables from this label. May requireparseTokens()to be called after, if any values for variables present in this Label used square-bracket or curly-brace markup. This doesn't check. -
act
public void act(float delta) - Overrides:
actin classcom.badlogic.gdx.scenes.scene2d.Actor
-
setSize
public void setSize(float width, float height) - Overrides:
setSizein classTextraLabel
-
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidthin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefWidthin classTextraLabel
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeightin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefHeightin classTextraLabel
-
layout
public void layout()- Specified by:
layoutin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
layoutin classTextraLabel
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) If your font usesFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, then this has to do some extra work to use the appropriate shader. IfFont.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:
drawin classTextraLabel- Parameters:
batch- probably should be a SpriteBatchparentAlpha- the alpha of the parent container, or 1.0f if there is none
-
drawSection
public void drawSection(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha, int startIndex, int endIndex) Renders a subsection of the glyphs in this label. If your font usesFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, then this has to do some extra work to use the appropriate shader. IfFont.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.- Parameters:
batch- probably should be a SpriteBatchparentAlpha- the alpha of the parent container, or 1.0f if there is nonestartIndex- the first index, inclusive, to start rendering atendIndex- the last index, exclusive, to stop rendering before; if negative this won't be limited
-
toString
- Overrides:
toStringin classTextraLabel
-
getSelectedText
If this label isselectableand there is a selected range of text, this returns that range of text; otherwise, it returns the empty string.- Returns:
- the currently selected text, or the empty string if none is or can be selected
-
copySelectedText
public boolean copySelectedText()If this label isselectableand there is a selected range of text, this copies that range of text to the clipboard and returns true; otherwise, it returns false.- Returns:
- true if text was copied, or false if the clipboard hasn't received any text
-
hasSelection
public boolean hasSelection()If this label isselectableand there is a selected range of text, this returns true; otherwise, it returns false.- Returns:
- true if there is selected text, or false otherwise
-
setIntermediateText
-
getIntermediateText
-
getInLayout
-
getInWorkingLayout
public long getInWorkingLayout(int index) -
getWorkingLayout
Returns the meant-for-internal-use-only Layout that is frequently changed as this label is displayed. The working layout may be useful to have, even if treated as read-only, so it is exposed here. Still, be very careful with this method and the Layout it returns. The working layout is the one that gets shown, wherelayout()is used as the ideal text before wrapping or other requirements edit it. The gettersgetRotations(),getSizing(),getOffsets(), andgetAdvances()refer to the working layout's fieldsLayout.rotations,Layout.sizing, andLayout.offsets, andLayout.advances, respectively.- Returns:
- the mostly-internal working layout, which is the layout that gets displayed.
-
getMaxLines
public int getMaxLines()The maximum number ofLines this label can display.- Overrides:
getMaxLinesin classTextraLabel- Returns:
- the maximum number of
Lineobjects this label can display
-
setMaxLines
public void setMaxLines(int maxLines) Sets the maximum number ofLines this Layout can display; this is always at least 1. For effectively unlimited lines, passInteger.MAX_VALUEto this.- Overrides:
setMaxLinesin classTextraLabel- Parameters:
maxLines- the limit for how many Line objects this Layout can display; always 1 or more
-
getEllipsis
Gets the ellipsis, which may be null, or may be a String that can be placed at the end of the text if its max lines are exceeded.- Overrides:
getEllipsisin classTextraLabel- Returns:
- an ellipsis String or null
-
setEllipsis
Sets the ellipsis text, which replaces the last few glyphs if non-null and the text added would exceed thegetMaxLines()of this label's working layout. For the ellipsis to appear, this has to be called with a non-null String (often"...", or"…"if the font supports it), andsetMaxLines(int)needs to have been called with a small enough number, such as 1.- Overrides:
setEllipsisin classTextraLabel- Parameters:
ellipsis- a String for a Layout to end with if its max lines are exceeded, or null to avoid such truncation
-
substring
Gets a String from the working layout of this label, made of only the char portions of the glyphs from start (inclusive) to end (exclusive). This can retrieve text from across multiple lines.- Overrides:
substringin classTextraLabel- Parameters:
start- inclusive start indexend- exclusive end index- Returns:
- a String made of only the char portions of the glyphs from start to end
-
getLineInLayout
-
getLineHeight
public float getLineHeight(int index) Gets the height of the Line containing the glyph at the given index, in the working layout. If the index is out of bounds, this just returnsFont.cellHeight.- Overrides:
getLineHeightin classTextraLabel- Parameters:
index- the 0-based index of the glyph to measure- Returns:
- the height of the Line containing the specified glyph
-
getCumulativeLineHeight
public float getCumulativeLineHeight(int index) Gets the height of the Line containing the glyph at the given index, plus the heights of all preceding lines, in the working layout. If the index is out of bounds, this returns either 0 if index was too low, or the height of all lines together if the index was too high.- Parameters:
index- the 0-based index of the glyph to measure- Returns:
- the sum of the height of the Line containing the specified glyph and all preceding line heights
-
getFromIntermediate
public long getFromIntermediate(int index) -
setInLayout
-
insertInLayout
-
insertInLayout
-
setInWorkingLayout
public void setInWorkingLayout(int index, long newGlyph) -
length
public int length()Gets the length in glyphs of the working layout (what is displayed).- Returns:
- the length in glyphs of the working layout (what is displayed)
-
triggerEvent
Triggers an event with the given String name. Ifalwaysis true, this will trigger the event even if the typing animation has already ended. This requires aTypingListenerto be set.- Parameters:
event- the event name to triggeralways- if true, the event will be triggered even if the animation has finished.
-
isSelectable
public boolean isSelectable()Returns true if and only ifselectableis true andtrackingInputis true; otherwise false.- Returns:
- whether the text of this label is selectable
-
setSelectable
If giventrue, this makes the text of this labelselectableand ensurestrackingInputis true. Otherwise, this makes the label not-selectable and doesn't changetrackingInput. The application should usually be set to copy the selected text usingcopySelectedText()when the user expects it to be copied. Often, aTypingListenerthat checks for the event"*SELECTED"works. This also sets theselectionDrawableto something nicer-looking than the default, but it can only do this ifTextraLabel.fonthas aFont.solidBlock.- Parameters:
selectable- true if the text of this label should be selectable- Returns:
- this, for chaining
-
getTextSpeed
public float getTextSpeed() -
setTextSpeed
public void setTextSpeed(float textSpeed) -
getRotations
public com.badlogic.gdx.utils.FloatArray getRotations()Contains one float per glyph; each is a rotation in degrees to apply to that glyph (around its center). This should not be confused withActor.getRotation(), which refers to the rotation of the label itself. This getter accesses the rotation of each glyph around its center instead. This is a direct reference to the currentworking layout'sLayout.rotations.- Overrides:
getRotationsin classTextraLabel
-
getOffsets
public com.badlogic.gdx.utils.FloatArray getOffsets()Contains two floats per glyph; even items are x offsets, odd items are y offsets. This getter accesses the x- and y-offsets of each glyph from its normal position. This is a direct reference to the currentworking layout'sLayout.offsets.- Overrides:
getOffsetsin classTextraLabel
-
getSizing
public com.badlogic.gdx.utils.FloatArray getSizing()Contains two floats per glyph, as size multipliers; even items apply to x, odd items apply to y. This getter accesses the x-and y-scaling of each glyph in its normal location, without changing line height or the x-advance of each glyph. It is usually meant for temporary or changing effects, not permanent scaling. This is a direct reference to the currentworking layout'sLayout.sizing.- Overrides:
getSizingin classTextraLabel
-
getAdvances
public com.badlogic.gdx.utils.FloatArray getAdvances()Contains one float per glyph; each is a multiplier that affects the x-advance of that glyph. This getter uses the same types of values asgetSizing(), so if you change the x-scaling of a glyph with that variable, you can also change its x-advance here by assigning the same value for that glyph here. This is a direct reference to the currentworking layout'sLayout.rotations.- Overrides:
getAdvancesin classTextraLabel
-