libgdx API

com.badlogic.gdx.scenes.scene2d.ui
Class Label

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.ui.Widget
          extended by com.badlogic.gdx.scenes.scene2d.ui.Label
All Implemented Interfaces:
Layout

public class Label
extends Widget

A text label, with optional word wrapping.

Unlike most scene2d.ui widgets, label can be scaled and rotated using the actor's scale, rotation, and origin. This only affects drawing, other scene2d.ui widgets will still use the unscaled and unrotated bounds of the label. Note that a scaled or rotated label causes a SpriteBatch flush when it is drawn, so should be used relatively sparingly.

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

Author:
Nathan Sweet

Nested Class Summary
static class Label.LabelStyle
          The style for a label, see Label.
 
Constructor Summary
Label(java.lang.CharSequence text, Label.LabelStyle style)
           
Label(java.lang.CharSequence text, Skin skin)
           
Label(java.lang.CharSequence text, Skin skin, java.lang.String styleName)
           
Label(java.lang.CharSequence text, Skin skin, java.lang.String fontName, Color color)
          Creates a label, using a Label.LabelStyle that has a BitmapFont with the specified name from the skin and the specified color.
Label(java.lang.CharSequence text, Skin skin, java.lang.String fontName, java.lang.String colorName)
          Creates a label, using a Label.LabelStyle that has a BitmapFont with the specified name and the specified color from the skin.
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.
 float getFontScaleX()
           
 float getFontScaleY()
           
 float getPrefHeight()
           
 float getPrefWidth()
           
 Label.LabelStyle getStyle()
          Returns the label's style.
 java.lang.CharSequence getText()
           
 BitmapFont.TextBounds getTextBounds()
           
 void invalidate()
          Invalidates this actor's layout, causing Layout.layout() to happen the next time Layout.validate() is called.
 void layout()
          Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls Layout.invalidate() any each child whose width or height has changed, and calls Layout.validate() on each child.
 void setAlignment(int wrapAlign)
           
 void setAlignment(int labelAlign, int lineAlign)
           
 void setFontScale(float fontScale)
           
 void setFontScale(float fontScaleX, float fontScaleY)
           
 void setFontScaleX(float fontScaleX)
           
 void setFontScaleY(float fontScaleY)
           
 void setStyle(Label.LabelStyle style)
           
 void setText(java.lang.CharSequence newText)
           
 void setWrap(boolean wrap)
          If false, the text will only wrap where it contains newlines (\n).
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, addAction, addCaptureListener, addListener, clearActions, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getWidth, getX, getY, getZIndex, hasParent, hit, isAscendantOf, isDescendantOf, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotate, scale, scale, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setParent, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setVisible, setWidth, setX, setY, setZIndex, size, size, stageToLocalCoordinates, toBack, toFront, toString, translate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Label

public Label(java.lang.CharSequence text,
             Skin skin)

Label

public Label(java.lang.CharSequence text,
             Skin skin,
             java.lang.String styleName)

Label

public Label(java.lang.CharSequence text,
             Skin skin,
             java.lang.String fontName,
             Color color)
Creates a label, using a Label.LabelStyle that has a BitmapFont with the specified name from the skin and the specified color.


Label

public Label(java.lang.CharSequence text,
             Skin skin,
             java.lang.String fontName,
             java.lang.String colorName)
Creates a label, using a Label.LabelStyle that has a BitmapFont with the specified name and the specified color from the skin.


Label

public Label(java.lang.CharSequence text,
             Label.LabelStyle style)
Method Detail

setStyle

public void setStyle(Label.LabelStyle style)

getStyle

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


setText

public void setText(java.lang.CharSequence newText)
Parameters:
newText - May be null.

getText

public java.lang.CharSequence getText()

invalidate

public void invalidate()
Description copied from interface: Layout
Invalidates this actor's layout, causing Layout.layout() to happen the next time Layout.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).

Specified by:
invalidate in interface Layout
Overrides:
invalidate in class Widget

layout

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

Specified by:
layout in interface Layout
Overrides:
layout in class Widget

draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
Description copied from class: Widget
If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.

Overrides:
draw in class Widget
parentAlpha - Should be multipied with the actor's alpha, allowing a parent's alpha to affect all children.

getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout
Overrides:
getPrefWidth in class Widget

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout
Overrides:
getPrefHeight in class Widget

getTextBounds

public BitmapFont.TextBounds getTextBounds()

setWrap

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 the something external will set the width of the label. Default is false.


setAlignment

public void setAlignment(int wrapAlign)
Parameters:
wrapAlign - Aligns each line of text horizontally and all the text vertically.
See Also:
Align

setAlignment

public void setAlignment(int labelAlign,
                         int lineAlign)
Parameters:
labelAlign - Aligns all the text with the label widget.
lineAlign - Aligns each line of text (left, right, or center).
See Also:
Align

setFontScale

public void setFontScale(float fontScale)

setFontScale

public void setFontScale(float fontScaleX,
                         float fontScaleY)

getFontScaleX

public float getFontScaleX()

setFontScaleX

public void setFontScaleX(float fontScaleX)

getFontScaleY

public float getFontScaleY()

setFontScaleY

public void setFontScaleY(float fontScaleY)

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)