Class GlyphLayout
- java.lang.Object
-
- com.badlogic.gdx.graphics.g2d.GlyphLayout
-
- All Implemented Interfaces:
Pool.Poolable
public class GlyphLayout extends java.lang.Object implements Pool.Poolable
Storesrunsof glyphs for a piece of text. The text may contain newlines and color markup tags.Where wrapping occurs is determined by
BitmapFont.BitmapFontData.getWrapIndex(Array, int). Additionally, whenBitmapFont.BitmapFontData.markupEnabledis true wrapping can occur at color start or end tags.When wrapping occurs, whitespace is removed before and after the wrap position. Whitespace is determined by
BitmapFont.BitmapFontData.isWhitespace(char).Glyphs positions are determined by
BitmapFont.BitmapFontData.getGlyphs(GlyphRun, CharSequence, int, int, Glyph).This class is not thread safe, even if synchronized externally, and must only be used from the game thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGlyphLayout.GlyphRunStores glyphs and positions for a line of text.
-
Field Summary
Fields Modifier and Type Field Description IntArraycolorsDetermines the colors of the glpyhs in theruns.intglyphCountNumber of glyphs across allruns.floatheightArray<GlyphLayout.GlyphRun>runsEach run has the glyphs for a line of text.floatwidth
-
Constructor Summary
Constructors Constructor Description GlyphLayout()Creates an empty GlyphLayout.GlyphLayout(BitmapFont font, java.lang.CharSequence str)GlyphLayout(BitmapFont font, java.lang.CharSequence str, int start, int end, Color color, float targetWidth, int halign, boolean wrap, java.lang.String truncate)GlyphLayout(BitmapFont font, java.lang.CharSequence str, Color color, float targetWidth, int halign, boolean wrap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidreset()Resets the object for reuse.voidsetText(BitmapFont font, java.lang.CharSequence str)CallssetTextwith the whole string, the font's current color, and no alignment or wrapping.voidsetText(BitmapFont font, java.lang.CharSequence str, int start, int end, Color color, float targetWidth, int halign, boolean wrap, java.lang.String truncate)voidsetText(BitmapFont font, java.lang.CharSequence str, Color color, float targetWidth, int halign, boolean wrap)CallssetTextwith the whole string and no truncation.java.lang.StringtoString()
-
-
-
Field Detail
-
runs
public final Array<GlyphLayout.GlyphRun> runs
Each run has the glyphs for a line of text.Runs are pooled, so references should not be kept past the next call to
setText(BitmapFont, CharSequence, int, int, Color, float, int, boolean, String)orreset().
-
colors
public final IntArray colors
Determines the colors of the glpyhs in theruns. Entries are pairs where the first is the glyph index (across all runs) where the color starts and the second is the color encoded as ABGR8888.For example:
[0, WHITE, 4, GREEN, 5, WHITE]
Glpyhs 0 to 3 are WHITE, 4 is GREEN and 5 to the end are WHITE.The array is empty if there are no runs, otherwise it has at least two entries:
[0, startColor]
-
glyphCount
public int glyphCount
Number of glyphs across allruns.
-
width
public float width
-
height
public float height
-
-
Constructor Detail
-
GlyphLayout
public GlyphLayout()
Creates an empty GlyphLayout.
-
GlyphLayout
public GlyphLayout(BitmapFont font, java.lang.CharSequence str)
- See Also:
setText(BitmapFont, CharSequence)
-
GlyphLayout
public GlyphLayout(BitmapFont font, java.lang.CharSequence str, Color color, float targetWidth, int halign, boolean wrap)
- See Also:
setText(BitmapFont, CharSequence)
-
GlyphLayout
public GlyphLayout(BitmapFont font, java.lang.CharSequence str, int start, int end, Color color, float targetWidth, int halign, boolean wrap, java.lang.String truncate)
- See Also:
setText(BitmapFont, CharSequence)
-
-
Method Detail
-
setText
public void setText(BitmapFont font, java.lang.CharSequence str)
CallssetTextwith the whole string, the font's current color, and no alignment or wrapping.
-
setText
public void setText(BitmapFont font, java.lang.CharSequence str, Color color, float targetWidth, int halign, boolean wrap)
CallssetTextwith the whole string and no truncation.
-
setText
public void setText(BitmapFont font, java.lang.CharSequence str, int start, int end, Color color, float targetWidth, int halign, boolean wrap, @Null java.lang.String truncate)
- Parameters:
color- The default color to use for the text (the BitmapFontcoloris not used). IfBitmapFont.BitmapFontData.markupEnabledis true, color markup tags in the specified string may change the color for portions of the text.halign- Horizontal alignment of the text, seeAlign.targetWidth- The width used for alignment, line wrapping, and truncation. May be zero if those features are not used.truncate- If not null and the width of the glyphs exceed targetWidth, the glyphs are truncated and the glyphs for the specified truncate string are placed at the end. Empty string can be used to truncate without adding glyphs. Truncate should not be used with text that contains multiple lines. Wrap is ignored if truncate is not null.
-
reset
public void reset()
Description copied from interface:Pool.PoolableResets the object for reuse. Object references should be nulled and fields may be set to default values.- Specified by:
resetin interfacePool.Poolable
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-