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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLabel.LabelStyleThe style for a label, seeLabel.
-
Constructor Summary
Constructors Constructor Description 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 aLabel.LabelStylethat 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 aLabel.LabelStylethat has a BitmapFont with the specified name and the specified color from the skin.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcomputePrefSize(GlyphLayout layout)voiddraw(Batch batch, float parentAlpha)If this method is overridden, the super method orWidget.validate()should be called to ensure the widget is laid out.protected BitmapFontCachegetBitmapFontCache()Allows subclasses to access the cache indraw(Batch, float).floatgetFontScaleX()floatgetFontScaleY()GlyphLayoutgetGlyphLayout()intgetLabelAlign()intgetLineAlign()floatgetPrefHeight()floatgetPrefWidth()Label.LabelStylegetStyle()Returns the label's style.StringBuildergetText()booleangetWrap()voidinvalidate()Invalidates this actor's layout, causingLayout.layout()to happen the next timeLayout.validate()is called.voidlayout()Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsLayout.invalidate()on any each child whose width or height has changed, and callsLayout.validate()on each child.voidsetAlignment(int alignment)voidsetAlignment(int labelAlign, int lineAlign)voidsetEllipsis(boolean ellipsis)When true the text will be truncated "..." if it does not fit within the width of the label.voidsetEllipsis(java.lang.String ellipsis)When non-null the text will be truncated "..." if it does not fit within the width of the label.voidsetFontScale(float fontScale)voidsetFontScale(float fontScaleX, float fontScaleY)voidsetFontScaleX(float fontScaleX)voidsetFontScaleY(float fontScaleY)voidsetStyle(Label.LabelStyle style)booleansetText(int value)Sets the text to the specified integer value.voidsetText(java.lang.CharSequence newText)voidsetWrap(boolean wrap)If false, the text will only wrap where it contains newlines (\n).booleantextEquals(java.lang.CharSequence other)java.lang.StringtoString()-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, drawDebugBounds, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, hit, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
-
-
-
Constructor Detail
-
Label
public Label(@Null java.lang.CharSequence text, Skin skin, java.lang.String fontName, Color color)
Creates a label, using aLabel.LabelStylethat has a BitmapFont with the specified name from the skin and the specified color.
-
Label
public Label(@Null java.lang.CharSequence text, Skin skin, java.lang.String fontName, java.lang.String colorName)
Creates a label, using aLabel.LabelStylethat has a BitmapFont with the specified name and the specified color from the skin.
-
Label
public Label(@Null 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 untilsetStyle(LabelStyle)is called.
-
setText
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:
- true if the text was changed.
-
setText
public void setText(@Null java.lang.CharSequence newText)
- Parameters:
newText- If null, "" will be used.
-
textEquals
public boolean textEquals(java.lang.CharSequence other)
-
getText
public StringBuilder getText()
-
invalidate
public void invalidate()
Description copied from interface:LayoutInvalidates this actor's layout, causingLayout.layout()to happen the next timeLayout.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:
invalidatein interfaceLayout- Overrides:
invalidatein classWidget
-
computePrefSize
protected void computePrefSize(GlyphLayout layout)
-
layout
public void layout()
Description copied from interface:LayoutComputes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsLayout.invalidate()on any each child whose width or height has changed, and callsLayout.validate()on each child. This method should almost never be called directly, insteadLayout.validate()should be used.
-
draw
public void draw(Batch batch, float parentAlpha)
Description copied from class:WidgetIf this method is overridden, the super method orWidget.validate()should be called to ensure the widget is laid out.
-
getPrefWidth
public float getPrefWidth()
- Specified by:
getPrefWidthin interfaceLayout- Overrides:
getPrefWidthin classWidget
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeightin interfaceLayout- Overrides:
getPrefHeightin classWidget
-
getGlyphLayout
public GlyphLayout getGlyphLayout()
-
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 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.
-
getWrap
public boolean getWrap()
-
getLabelAlign
public int getLabelAlign()
-
getLineAlign
public int getLineAlign()
-
setAlignment
public void setAlignment(int alignment)
- Parameters:
alignment- Aligns all the text within the label (default left center) and each line of text horizontally (default left).- See Also:
Align
-
setAlignment
public void setAlignment(int labelAlign, int lineAlign)- Parameters:
labelAlign- Aligns all the text within the label (default left center).lineAlign- Aligns each line of text horizontally (default left).- 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)
-
setEllipsis
public void setEllipsis(@Null java.lang.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.
-
setEllipsis
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.
-
getBitmapFontCache
protected BitmapFontCache getBitmapFontCache()
Allows subclasses to access the cache indraw(Batch, float).
-
-