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 label.

Functionality

A Label displays multi-line text.

Layout

The (preferred) width and height of a Label are derrived from the bounding box of the text contained in it. Use Widget.setPrefSize(int, int) to change this programmatically. If the text doesn't fit into the specified area artifacts will be visible.

Style

A label is a Widget displaying text via a BitmapFont and a Color. The style is defined via an instance of Label.LabelStyle, which can be either done programmatically or via a Skin. A label's text will always be rendered starting from the top edge of it's bouding box, define by its width and height, not the text's bounding box. A Label's style definition in a skin XML file should look like this:
 <label name="styleName" 
        font="fontName" 
        color="colorName"
                    />
 
 

Author:
mzechner

Nested Class Summary
static class Label.LabelStyle
          Defines a label's style, see Label
 
Field Summary
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
invalidated, prefHeight, prefWidth
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, touchable, visible, width, x, y
 
Constructor Summary
Label(java.lang.String text, Label.LabelStyle style)
           
Label(java.lang.String text, Skin skin)
           
Label(java.lang.String name, java.lang.String text, Label.LabelStyle style)
           
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          Draws the Actor.
 Color getColor()
           
 java.lang.String getText()
           
 Actor hit(float x, float y)
           
 void layout()
          Positions and sizes each child of this actor.
 void setColor(Color tint)
           
 void setColor(float color)
           
 void setColor(float r, float g, float b, float a)
           
 void setStyle(Label.LabelStyle style)
          Sets the style of this widget.
 void setText(java.lang.String text)
           
 boolean touchDown(float x, float y, int pointer)
           
 void touchDragged(float x, float y, int pointer)
           
 void touchUp(float x, float y, int pointer)
           
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getPrefHeight, getPrefWidth, invalidate, invalidateHierarchy, setPrefSize
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, 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(java.lang.String text,
             Skin skin)

Label

public Label(java.lang.String text,
             Label.LabelStyle style)

Label

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

setStyle

public void setStyle(Label.LabelStyle style)
Sets the style of this widget. Calls Widget.invalidateHierarchy() internally.

Parameters:
style -

setText

public void setText(java.lang.String text)

getText

public java.lang.String getText()

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
Positions and sizes each child of this actor. Subsequent calls will not have any affect unless Layout.invalidate() is called.


draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
Description copied from class: Actor
Draws the Actor. The spriteBatch is configured so that the Actor can draw in its parents coordinate system. The parent's alpha is passed to the method in order for the Actor to multiply it with its own alpha. This will allow FadeIn and other Actions to have an effect even if they are only set on the parent of the Actor.

Specified by:
draw in class Actor
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

touchDown

public boolean touchDown(float x,
                         float y,
                         int pointer)
Specified by:
touchDown in class Actor

touchUp

public void touchUp(float x,
                    float y,
                    int pointer)
Specified by:
touchUp in class Actor

touchDragged

public void touchDragged(float x,
                         float y,
                         int pointer)
Specified by:
touchDragged in class Actor

hit

public Actor hit(float x,
                 float y)
Overrides:
hit in class Widget

libgdx API

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