APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.ui

public Class Label

extends Widget
implements Styleable<Label.LabelStyle>
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.ui.Styleable
Imports
com.badlogic.gdx.graphics.Color, com.badlogic.gdx.graphics.g2d.Batch, .BitmapFont, .BitmapFontCache, .GlyphLayout, com.badlogic.gdx.scenes.scene2d.utils.Drawable, com.badlogic.gdx.utils.Align, .CharArray, .Justify, .Null

A text label, with optional word wrapping.

The preferred size of the label is determined by the actual text bounds, unless word wrap is enabled.

Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Label.LabelStyle

The style for a label, see Label.

Field Summary

Modifier and TypeField and Description
private BitmapFontCache
private String
private boolean
private float
private float
private int
private Justify
private int
private float
private final GlyphLayout
private int
private float
private boolean
private static final GlyphLayout
private float
private Label.LabelStyle
private static final Color
private final CharArray
private boolean

Constructor Summary

AccessConstructor and Description
public
Label(CharSequence text, Skin skin)

public
Label(CharSequence text, Skin skin, String styleName)

public
Label(CharSequence text, Skin skin, String fontName, Color color)

Creates a label, using a LabelStyle that has a BitmapFont with the specified name from the skin and the specified color.

public
Label(CharSequence text, Skin skin, String fontName, String colorName)

Creates a label, using a LabelStyle that has a BitmapFont with the specified name and the specified color from the skin.

public

Method Summary

Modifier and TypeMethod and Description
protected void
public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

protected BitmapFontCache
getBitmapFontCache()

Allows subclasses to access the cache in draw(Batch, float).

public float
public float
public GlyphLayout
public Justify
public int
public int
public float
public float
public Label.LabelStyle
getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the label's style.

public CharArray
public boolean
public void
invalidate()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.invalidate.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.invalidate.

Invalidates this actor's layout, causing layout() to happen the next time validate() is called.

public void
layout()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.layout.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child.

private void
public void
setAlignment(int
Aligns all the text within the label (default left center) and each line of text horizontally (default left).
alignment
)

public void
setAlignment(int
Aligns all the text within the label (default left center).
labelAlign
,
int
Aligns each line of text horizontally (default left).
lineAlign
)

public void
setEllipsis(String ellipsis)

When non-null the text will be truncated "..." if it does not fit within the width of the label.

public void
setEllipsis(boolean ellipsis)

When true the text will be truncated "..." if it does not fit within the width of the label.

public void
setFontScale(float fontScale)

public void
setFontScale(float fontScaleX, float fontScaleY)

public void
setFontScaleX(float fontScaleX)

public void
setFontScaleY(float fontScaleY)

public void
setJustify(Justify
Justifies text to the label widths (disabled by default).
justify
)

public void
setStyle(Label.LabelStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

public boolean

Returns:

true if the text was changed.
setText
(int value)

Sets the text to the specified integer value.

public void
setText(CharSequence
If null, "" will be used.
newText
)

public void
setWrap(boolean wrap)

If false, the text will only wrap where it contains newlines (\n).

public boolean
public String
toString()

Overrides com.badlogic.gdx.scenes.scene2d.Actor.toString.

Returns a string representation of the object.

Inherited from com.badlogic.gdx.scenes.scene2d.ui.Widget:
getMaxHeightgetMaxWidthgetMinHeightgetMinWidthinvalidateHierarchyneedsLayoutpacksetFillParentsetLayoutEnabledsizeChangedvalidate

Field Detail

cacheback to summary
private BitmapFontCache cache
ellipsisback to summary
private String ellipsis
Annotations
@Null
fontScaleChangedback to summary
private boolean fontScaleChanged
fontScaleXback to summary
private float fontScaleX
fontScaleYback to summary
private float fontScaleY
intValueback to summary
private int intValue
justifyback to summary
private Justify justify
labelAlignback to summary
private int labelAlign
lastPrefHeightback to summary
private float lastPrefHeight
layoutback to summary
private final GlyphLayout layout
lineAlignback to summary
private int lineAlign
prefHeightback to summary
private float prefHeight
prefSizeInvalidback to summary
private boolean prefSizeInvalid
prefSizeLayoutback to summary
private static final GlyphLayout prefSizeLayout
prefWidthback to summary
private float prefWidth
styleback to summary
private Label.LabelStyle style
tempColorback to summary
private static final Color tempColor
textback to summary
private final CharArray text
wrapback to summary
private boolean wrap

Constructor Detail

Labelback to summary
public Label(CharSequence text, Skin skin)
Labelback to summary
public Label(CharSequence text, Skin skin, String styleName)
Labelback to summary
public Label(CharSequence text, Skin skin, String fontName, Color color)

Creates a label, using a LabelStyle that has a BitmapFont with the specified name from the skin and the specified color.

Labelback to summary
public Label(CharSequence text, Skin skin, String fontName, String colorName)

Creates a label, using a LabelStyle that has a BitmapFont with the specified name and the specified color from the skin.

Labelback to summary
public Label(CharSequence text, Label.LabelStyle style)

Method Detail

computePrefSizeback to summary
protected void computePrefSize(GlyphLayout layout)
drawback to summary
public void draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

getBitmapFontCacheback to summary
protected BitmapFontCache getBitmapFontCache()

Allows subclasses to access the cache in draw(Batch, float).

getFontScaleXback to summary
public float getFontScaleX()
getFontScaleYback to summary
public float getFontScaleY()
getGlyphLayoutback to summary
public GlyphLayout getGlyphLayout()
getJustifyback to summary
public Justify getJustify()
getLabelAlignback to summary
public int getLabelAlign()
getLineAlignback to summary
public int getLineAlign()
getPrefHeightback to summary
public float getPrefHeight()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefHeight.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefHeight.

getPrefWidthback to summary
public float getPrefWidth()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefWidth.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefWidth.

getStyleback to summary
public Label.LabelStyle getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the label's style. Modifying the returned style may not have an effect until setStyle(LabelStyle) is called.

getTextback to summary
public CharArray getText()
getWrapback to summary
public boolean getWrap()
invalidateback to summary
public void invalidate()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.invalidate.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.invalidate.

Doc from com.badlogic.gdx.scenes.scene2d.utils.Layout.invalidate.

Invalidates this actor's layout, causing layout() to happen the next time validate() is called. This method should be called when state changes in the actor that requires a layout but does not change the minimum, preferred, maximum, or actual size of the actor (meaning it does not affect the parent actor's layout).

layoutback to summary
public void layout()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.layout.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Doc from com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child. This method should almost never be called directly, instead validate() should be used.

scaleAndComputePrefSizeback to summary
private void scaleAndComputePrefSize()
setAlignmentback to summary
public void setAlignment(int alignment)
Parameters
alignment:int

Aligns all the text within the label (default left center) and each line of text horizontally (default left).

See Also
Align
setAlignmentback to summary
public void setAlignment(int labelAlign, int lineAlign)
Parameters
labelAlign:int

Aligns all the text within the label (default left center).

lineAlign:int

Aligns each line of text horizontally (default left).

See Also
Align
setEllipsisback to summary
public void setEllipsis(String ellipsis)

When non-null the text will be truncated "..." if it does not fit within the width of the label. Wrapping will not occur when ellipsis is enabled. Default is false.

setEllipsisback to summary
public void setEllipsis(boolean ellipsis)

When true the text will be truncated "..." if it does not fit within the width of the label. Wrapping will not occur when ellipsis is true. Default is false.

setFontScaleback to summary
public void setFontScale(float fontScale)
setFontScaleback to summary
public void setFontScale(float fontScaleX, float fontScaleY)
setFontScaleXback to summary
public void setFontScaleX(float fontScaleX)
setFontScaleYback to summary
public void setFontScaleY(float fontScaleY)
setJustifyback to summary
public void setJustify(Justify justify)
Parameters
justify:Justify

Justifies text to the label widths (disabled by default).

See Also
Justify
setStyleback to summary
public void setStyle(Label.LabelStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

setTextback to summary
public boolean setText(int value)

Sets the text to the specified integer value. If the text is already equivalent to the specified value, a string is not allocated.

Returns:boolean

true if the text was changed.

setTextback to summary
public void setText(CharSequence newText)
Parameters
newText:CharSequence

If null, "" will be used.

setWrapback to summary
public void setWrap(boolean wrap)

If false, the text will only wrap where it contains newlines (\n). The preferred size of the label will be the text bounds. If true, the text will word wrap using the width of the label. The preferred width of the label will be 0, it is expected that something external will set the width of the label. Wrapping will not occur when ellipsis is enabled. Default is false.

When wrap is enabled, the label's preferred height depends on the width of the label. In some cases the parent of the label will need to layout twice: once to set the width of the label and a second time to adjust to the label's new preferred height.

textEqualsback to summary
public boolean textEquals(CharSequence other)
toStringback to summary
public String toString()

Overrides com.badlogic.gdx.scenes.scene2d.Actor.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

com.badlogic.gdx.scenes.scene2d.ui back to summary

public Class Label.LabelStyle

extends Object
Class Inheritance

The style for a label, see Label.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
public Drawable
public BitmapFont
public Color

Constructor Summary

AccessConstructor and Description
public
public
LabelStyle(BitmapFont font, Color fontColor)

public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backgroundback to summary
public Drawable background
Annotations
@Null
fontback to summary
public BitmapFont font
fontColorback to summary
public Color fontColor
Annotations
@Null

Constructor Detail

LabelStyleback to summary
public LabelStyle()
LabelStyleback to summary
public LabelStyle(BitmapFont font, Color fontColor)
LabelStyleback to summary
public LabelStyle(Label.LabelStyle style)