com.badlogic.gdx.scenes.scene2d.ui
Class Label
java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
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
#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"
/>
- The
name
attribute defines the name of the style which you can later use with
Skin#newLabel(String, String, String)
.
- The
font
attribute references a BitmapFont
by name, to be used to render the label's text.
- The
fontColor
attribute references a Color
by name, to be used to render the label's text.
- Author:
- mzechner
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 |
Method Summary |
void |
draw(SpriteBatch batch,
float parentAlpha)
Draws the Actor. |
Color |
getColor()
|
float |
getPrefHeight()
|
float |
getPrefWidth()
|
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)
|
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.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 |
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 text,
Label.LabelStyle style,
java.lang.String name)
setStyle
public void setStyle(Label.LabelStyle 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 withparentAlpha
- 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
getPrefWidth
public float getPrefWidth()
getPrefHeight
public float getPrefHeight()
Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)