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.

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.
 
Field Summary
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, stage, touchable, visible, width, x, y
 
Constructor Summary
Label(java.lang.CharSequence text, Label.LabelStyle style)
           
Label(java.lang.CharSequence text, Label.LabelStyle style, java.lang.String name)
           
Label(java.lang.CharSequence text, Skin skin)
           
Label(java.lang.CharSequence text, java.lang.String fontName, Color color, Skin skin)
          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, java.lang.String fontName, java.lang.String colorName, Skin skin)
          Creates a label, using a Label.LabelStyle that has a BitmapFont with the specified name and the specified color from the skin.
Label(Skin 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.
 Color getColor()
           
 float getPrefHeight()
           
 float getPrefWidth()
           
 Label.LabelStyle getStyle()
          Returns the label's style.
 java.lang.CharSequence getText()
           
 BitmapFont.TextBounds getTextBounds()
           
 void layout()
          Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child and calls Layout.invalidate() and then Layout.validate() on each one.
 void setAlignment(int wrapAlign)
           
 void setAlignment(int labelAlign, int lineAlign)
           
 void setColor(Color tint)
           
 void setColor(float color)
           
 void setColor(float r, float g, float b, float a)
           
 void setStyle(Label.LabelStyle style)
           
 void setText(java.lang.CharSequence text)
           
 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, hit, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, toScreenCoordinates, touchDown, touchDragged, touchUp, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, getStage, isMarkedToRemove, keyDown, keyTyped, keyUp, markToRemove, remove, scrolled, toLocalCoordinates, toString, touchMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Label

public Label(Skin skin)

Label

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

Label

public Label(java.lang.CharSequence text,
             java.lang.String fontName,
             Color color,
             Skin skin)
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,
             java.lang.String fontName,
             java.lang.String colorName,
             Skin skin)
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)

Label

public Label(java.lang.CharSequence text,
             Label.LabelStyle style,
             java.lang.String name)
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 text)

getText

public java.lang.CharSequence getText()

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

setColor

public void setColor(float color)

setColor

public void setColor(Color tint)

setColor

public void setColor(float r,
                     float g,
                     float b,
                     float a)

getColor

public Color getColor()

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 and calls Layout.invalidate() and then Layout.validate() on each one. Usually this should not 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
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

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

libgdx API

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