public class Layout
extends java.lang.Object
implements com.badlogic.gdx.utils.Pool.Poolable
Lines of text,
which can use color and style markup from Font, and can be drawn with
Font.drawGlyphs(Batch, Layout, float, float, int). This is a Poolable class, and you can obtain a Layout with
Layout.POOL.obtain() followed by setting the font, or just using a constructor.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
atLimit |
protected float |
baseColor |
protected java.lang.String |
ellipsis |
protected Font |
font |
protected com.badlogic.gdx.utils.Array<Line> |
lines |
protected int |
maxLines |
static com.badlogic.gdx.utils.Pool<Layout> |
POOL |
protected float |
targetWidth |
| Modifier and Type | Method and Description |
|---|---|
Layout |
add(long glyph)
Adds a
long glyph as processed by Font to store color and style info with the char. |
java.lang.StringBuilder |
appendInto(java.lang.StringBuilder sb)
Primarily used by
toString(), but can be useful if you want to append many Layouts into a StringBuilder. |
java.lang.StringBuilder |
appendIntoDirect(java.lang.StringBuilder sb)
Can be useful if you want to append many Layouts into a StringBuilder.
|
Layout |
clear() |
Layout |
font(Font font)
One of the ways to set the font on a Layout; this one returns this Layout for chaining.
|
float |
getBaseColor()
Gets the base color of the Layout, as the float bits of a Color.
|
java.lang.String |
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.
|
Font |
getFont() |
float |
getHeight() |
Line |
getLine(int i)
Gets a Line from this by its index.
|
int |
getMaxLines()
The maximum number of
Lines this Layout can contain. |
float |
getTargetWidth() |
float |
getWidth() |
Line |
insertLine(int index) |
int |
lines() |
Line |
peekLine() |
Line |
pushLine() |
void |
reset()
Resets the object for reuse.
|
void |
setBaseColor(com.badlogic.gdx.graphics.Color baseColor)
Sets the base color of the Layout; this is what font color will be used immediately after resetting
formatting with
[], as well as the initial color used by text that hasn't been formatted. |
void |
setBaseColor(float baseColor)
Sets the base color of the Layout; this is what font color will be used immediately after resetting
formatting with
[], as well as the initial color used by text that hasn't been formatted. |
void |
setEllipsis(java.lang.String ellipsis)
Sets the ellipsis text, which replaces the last few glyphs if non-null and the text added would exceed
the
getMaxLines() of this Layout. |
void |
setFont(Font font)
One of the ways to set the font on a Layout; this is a traditional setter.
|
void |
setMaxLines(int maxLines)
Sets the maximum number of
Lines this Layout can contain; this is always at least 1. |
Layout |
setTargetWidth(float targetWidth) |
java.lang.String |
toString() |
public static final com.badlogic.gdx.utils.Pool<Layout> POOL
protected Font font
protected final com.badlogic.gdx.utils.Array<Line> lines
protected int maxLines
protected boolean atLimit
protected java.lang.String ellipsis
protected float targetWidth
protected float baseColor
public Layout()
public Layout(Font font)
public Layout font(Font font)
font - the font to usepublic Font getFont()
public void setFont(Font font)
font - the font to usepublic Layout add(long glyph)
long glyph as processed by Font to store color and style info with the char.glyph - usually produced by Font to store color and style info with the charpublic Layout clear()
public float getWidth()
public float getHeight()
public int lines()
public Line getLine(int i)
i - index for the Line to fetch; must be at least 0 and less than lines().public Line peekLine()
public Line pushLine()
public Line insertLine(int index)
public float getTargetWidth()
public Layout setTargetWidth(float targetWidth)
public float getBaseColor()
[], as well as the initial color
used by text that hasn't been formatted. You can fill a Color object with this value using
Color.abgr8888ToColor(Color, float) (it modifies the Color you give it).public void setBaseColor(float baseColor)
[], as well as the initial color used by text that hasn't been formatted.
This takes the color as a primitive float, which you can get from a Color object with
Color.toFloatBits(), or in some cases from existing data produced by Font.baseColor - the float bits of a Color, as obtainable via Color.toFloatBits()public void setBaseColor(com.badlogic.gdx.graphics.Color baseColor)
[], as well as the initial color used by text that hasn't been formatted.
If the given Color is null, this treats it as white.baseColor - a Color to use for text that hasn't been formatted; if null, will be treated as whitepublic int getMaxLines()
Lines this Layout can contain.Line objects this Layout can containpublic void setMaxLines(int maxLines)
Lines this Layout can contain; this is always at least 1.maxLines - the limit for how many Line objects this Layout can contain; always 1 or morepublic java.lang.String getEllipsis()
public void setEllipsis(java.lang.String ellipsis)
getMaxLines() of this Layout. For the ellipsis to appear, this has to be called with a
non-null String (often "...", or "…" if the font supports it), and
setMaxLines(int) needs to have been called with a small enough number, such as 1.ellipsis - a String for a Layout to end with if its max lines are exceeded, or null to avoid such truncationpublic void reset()
reset in interface com.badlogic.gdx.utils.Pool.Poolablepublic java.lang.StringBuilder appendIntoDirect(java.lang.StringBuilder sb)
appendInto(StringBuilder).
This does not add or remove newlines from the Layout's contents, and can produce line breaks if they appear.sb - a non-null StringBuilder from the JDKpublic java.lang.StringBuilder appendInto(java.lang.StringBuilder sb)
toString(), but can be useful if you want to append many Layouts into a StringBuilder.
This treats instances of the character u0002 as '[', as the library does internally, instead of
potentially printing a gibberish character.
This does not add or remove newlines from the Layout's contents, and can produce line breaks if they appear.sb - a non-null StringBuilder from the JDKpublic java.lang.String toString()
toString in class java.lang.Object