Package com.github.tommyettinger.textra
Class TextraLabel
java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.github.tommyettinger.textra.TextraLabel
- All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Layout
- Direct Known Subclasses:
TypingLabel
public class TextraLabel
extends com.badlogic.gdx.scenes.scene2d.ui.Widget
-
Field Summary
Fields Modifier and Type Field Description intalignprotected FontfontLayoutlayoutjava.lang.StringstoredTextcom.badlogic.gdx.scenes.scene2d.ui.Label.LabelStylestylebooleanwrapIf true; allows text to wrap when it would go past the layout'stargetWidthand continue on the next line; if false, uses a very long target width and only adds newlines when they are in the label's text. -
Constructor Summary
Constructors Constructor Description TextraLabel()Creates a TextraLabel that uses the default libGDX font (lsans-15 in the current version) with white color.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style)Creates a TextraLabel with the given text (which may be multi-line) and using the given style.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, boolean makeGridGlyphs)Creates a TextraLabel with the given text (which may be multi-line) and using the given style.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, Font replacementFont)Creates a TextraLabel with the given text (which may be multi-line) and using the given style.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin)Creates a TextraLabel with the given text (which may be multi-line) and using the specified Skin's LabelStyle.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, boolean makeGridGlyphs)Creates a TextraLabel with the given text (which may be multi-line) and using the specified Skin's LabelStyle.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, Font replacementFont)Creates a TextraLabel with the given text (which may be multi-line) and using the default style from a Skin, replacing any font that would be drawn from the style withreplacementFont.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName)Creates a TextraLabel with the given text (which may be multi-line) and using the specified style from the given Skin.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, boolean makeGridGlyphs)Creates a TextraLabel with the given text (which may be multi-line) and using the specified style from the given Skin.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, com.badlogic.gdx.graphics.Color color)Creates a TextraLabel with the given text (which may be multi-line), using the specified style from the given Skin, with the default Color overridden by the given one.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, Font replacementFont)Creates a TextraLabel with the given text (which may be multi-line) and using the given style taken by name from a Skin, replacing any font that would be drawn from the style withreplacementFont.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, Font replacementFont, com.badlogic.gdx.graphics.Color color)Creates a TextraLabel with the given text (which may be multi-line) and using the given style taken by name from a Skin, replacing any font that would be drawn from the style withreplacementFont.TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, java.lang.String colorName)Creates a TextraLabel with the given text (which may be multi-line), using the specified style from the given Skin, with the default Color overridden by the color with the given name in the skin.TextraLabel(java.lang.String text, Font font)Creates a TextraLabel with the given text (which may be multi-line) and using the given Font.TextraLabel(java.lang.String text, Font font, com.badlogic.gdx.graphics.Color color)Creates a TextraLabel with the given text (which may be multi-line), using the given Font, and using the given default color. -
Method Summary
Modifier and Type Method Description voiddraw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)intgetAlignment()Gets the alignment for the text in this TextraLabel.FontgetFont()floatgetPrefHeight()floatgetPrefWidth()booleanisWrap()Gets the current wrapping mode.voidlayout()booleanremove()voidsetAlignment(int alignment)Sets the alignment for the text in this TextraLabel.voidsetFont(Font font)Sets the font to the specified Font and then regenerates the layout usingFont.regenerateLayout(Layout).voidsetFont(Font font, boolean regenerate)Just likesetFont(Font), except this only regenerates the layout ifregenerateis true.protected voidsetParent(com.badlogic.gdx.scenes.scene2d.Group parent)Called by the framework when an actor is added to or removed from a group.voidsetSize(float width, float height)voidsetStage(com.badlogic.gdx.scenes.scene2d.Stage stage)Called by the framework when this actor or any ascendant is added to a group that is in the stage.voidsetText(java.lang.String markupText)Changes the text in this TextraLabel to the given String, parsing any markup in it.TextraLabelsetWrap(boolean wrap)Sets the wrapping mode; if this changes the mode, then this invalidates the hierarchy.voidskipToTheEnd()By default, does nothing; this is overridden in TypingLabel to skip its text progression ahead.TextraLabeluseIntegerPositions(boolean integer)Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validateMethods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, 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, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
layout
-
font
-
align
public int align -
wrap
public boolean wrapIf true; allows text to wrap when it would go past the layout'stargetWidthand continue on the next line; if false, uses a very long target width and only adds newlines when they are in the label's text. This should typically be false for widgets that use scene2d.ui layout, but should be true for any widget that dynamically adjusts to fill an area with wrapped text. -
storedText
public java.lang.String storedText -
style
public com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style
-
-
Constructor Details
-
TextraLabel
public TextraLabel()Creates a TextraLabel that uses the default libGDX font (lsans-15 in the current version) with white color. -
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin)Creates a TextraLabel with the given text (which may be multi-line) and using the specified Skin's LabelStyle.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the default Label.LabelStyle will be obtained from this and used
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, boolean makeGridGlyphs)Creates a TextraLabel with the given text (which may be multi-line) and using the specified Skin's LabelStyle.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the default Label.LabelStyle will be obtained from this and usedmakeGridGlyphs- if true, the font should have a solid block glyph available, and underline/strikethrough may be drawn more clearly; if false, underline/strikethrough will use underscore/dash
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName)Creates a TextraLabel with the given text (which may be multi-line) and using the specified style from the given Skin.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the named Label.LabelStyle will be obtained from this and usedstyleName- the name of a Label.LabelStyle to use from the Skin
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, boolean makeGridGlyphs)Creates a TextraLabel with the given text (which may be multi-line) and using the specified style from the given Skin.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the named Label.LabelStyle will be obtained from this and usedstyleName- the name of a Label.LabelStyle to use from the SkinmakeGridGlyphs- if true, the font should have a solid block glyph available, and underline/strikethrough may be drawn more clearly; if false, underline/strikethrough will use underscore/dash
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, com.badlogic.gdx.graphics.Color color)Creates a TextraLabel with the given text (which may be multi-line), using the specified style from the given Skin, with the default Color overridden by the given one.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the named Label.LabelStyle will be obtained from this and usedstyleName- the name of a Label.LabelStyle to use from the Skincolor- the color to use for the font when unspecified (at the start and when reset)
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, java.lang.String colorName)Creates a TextraLabel with the given text (which may be multi-line), using the specified style from the given Skin, with the default Color overridden by the color with the given name in the skin.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the named Label.LabelStyle will be obtained from this and usedstyleName- the name of a Label.LabelStyle to use from the SkincolorName- the name in the skin of the color to use for the font when unspecified (at the start and when reset)
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style)Creates a TextraLabel with the given text (which may be multi-line) and using the given style.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingstyle- the Label.LabelStyle to use
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, boolean makeGridGlyphs)Creates a TextraLabel with the given text (which may be multi-line) and using the given style.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingstyle- the Label.LabelStyle to usemakeGridGlyphs- if true, the font should have a solid block glyph available, and underline/strikethrough may be drawn more clearly; if false, underline/strikethrough will use underscore/dash
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, Font replacementFont)Creates a TextraLabel with the given text (which may be multi-line) and using the default style from a Skin, replacing any font that would be drawn from the style withreplacementFont.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the default Label.LabelStyle will be obtained from this and usedreplacementFont- a Font that will be used in place of the one in style
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, Font replacementFont)Creates a TextraLabel with the given text (which may be multi-line) and using the given style taken by name from a Skin, replacing any font that would be drawn from the style withreplacementFont.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the named Label.LabelStyle will be obtained from this and usedstyleName- the name of a Label.LabelStyle to use from the SkinreplacementFont- a Font that will be used in place of the one in style
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName, Font replacementFont, com.badlogic.gdx.graphics.Color color)Creates a TextraLabel with the given text (which may be multi-line) and using the given style taken by name from a Skin, replacing any font that would be drawn from the style withreplacementFont.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingskin- the named Label.LabelStyle will be obtained from this and usedstyleName- the name of a Label.LabelStyle to use from the SkinreplacementFont- a Font that will be used in place of the one in stylecolor- the base color to use for the label, used when reset
-
TextraLabel
public TextraLabel(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, Font replacementFont)Creates a TextraLabel with the given text (which may be multi-line) and using the given style.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingstyle- the Label.LabelStyle to use, except for its fontreplacementFont- a Font that will be used in place of the one in style
-
TextraLabel
Creates a TextraLabel with the given text (which may be multi-line) and using the given Font.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingfont- a Font from this library, such as one obtained fromKnownFonts
-
TextraLabel
Creates a TextraLabel with the given text (which may be multi-line), using the given Font, and using the given default color.- Parameters:
text- the text to use; may be multi-line, but will default to not wrappingfont- a Font from this library, such as one obtained fromKnownFontscolor- the color to use for the font when unspecified (at the start and when reset)
-
-
Method Details
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)- Overrides:
drawin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidthin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefWidthin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeightin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefHeightin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
useIntegerPositions
-
isWrap
public boolean isWrap()Gets the current wrapping mode. When wrap is enabled, the preferred and/or min/max sizes must be used so this knows where to wrap. If wrap is disabled, lines that are too wide will just widen the size of the widget.- Returns:
- whether this is currently wrapping
-
setWrap
Sets the wrapping mode; if this changes the mode, then this invalidates the hierarchy. When wrap is enabled, the preferred and/or min/max sizes must be used so this knows where to wrap. If wrap is disabled, lines that are too wide will just widen the size of the widget.- Parameters:
wrap- whether to wrap or not
-
setSize
public void setSize(float width, float height)- Overrides:
setSizein classcom.badlogic.gdx.scenes.scene2d.Actor
-
layout
public void layout()- Specified by:
layoutin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
layoutin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getAlignment
public int getAlignment()Gets the alignment for the text in this TextraLabel. This is a constant inAlign.- Returns:
- the alignment used by this TextraLabel, as a constant from
Align - See Also:
Align
-
setAlignment
public void setAlignment(int alignment)Sets the alignment for the text in this TextraLabel.- Parameters:
alignment- a constant fromAlign- See Also:
Align
-
getFont
-
setFont
Sets the font to the specified Font and then regenerates the layout usingFont.regenerateLayout(Layout). This is equivalent to callingsetFont(Font, boolean)with true for regenerate. This won't regenerate the layout if the given font is equal to the current font for this TextraLabel.- Parameters:
font- the non-null font to use for this TextraLabel
-
setFont
Just likesetFont(Font), except this only regenerates the layout ifregenerateis true. (To contrast,setFont(Font)always regenerates the layout.) This won't regenerate the layout if the given font is equal to the current font for this TextraLabel.- Parameters:
font- the non-null font to use for this TextraLabelregenerate- if true, the layout will be re-wrapped and its size re-calculated for the new font
-
setText
public void setText(java.lang.String markupText)Changes the text in this TextraLabel to the given String, parsing any markup in it.- Parameters:
markupText- a String that can contain Font markup
-
skipToTheEnd
public void skipToTheEnd()By default, does nothing; this is overridden in TypingLabel to skip its text progression ahead. -
remove
public boolean remove()- Overrides:
removein classcom.badlogic.gdx.scenes.scene2d.Actor
-
setStage
public void setStage(com.badlogic.gdx.scenes.scene2d.Stage stage)Called by the framework when this actor or any ascendant is added to a group that is in the stage. This is overridden as public instead of protected because most of its usage in scene2d.ui code is not actually in inheriting classes, but in other classes in the same package. That's a problem here, so we make it public.- Overrides:
setStagein classcom.badlogic.gdx.scenes.scene2d.Actor- Parameters:
stage- May be null if the actor or any ascendant is no longer in a stage.
-
setParent
protected void setParent(com.badlogic.gdx.scenes.scene2d.Group parent)Called by the framework when an actor is added to or removed from a group. This is overridden as public instead of protected because most of its usage in scene2d.ui code is not actually in inheriting classes, but in other classes in the same package. That's a problem here, so we make it public.- Overrides:
setParentin classcom.badlogic.gdx.scenes.scene2d.Actor- Parameters:
parent- May be null if the actor has been removed from the parent.
-