Package com.prineside.tdi2.ui.actors
Class Label
java.lang.Object
com.prineside.tdi2.scene2d.Actor
com.prineside.tdi2.scene2d.ui.Widget
com.prineside.tdi2.ui.actors.Label
- All Implemented Interfaces:
Layout
- Direct Known Subclasses:
LabelButton
,LabelWithShadow
,LimitedWidthLabel
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
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
If this method is overridden, the super method orWidget.validate()
should be called to ensure the widget is laid out.float
float
int
int
float
float
getStyle()
Returns the label's style.getText()
boolean
getWrap()
void
Invalidates this actor's layout, causingLayout.layout()
to happen the next timeLayout.validate()
is called.void
layout()
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.void
setAlignment
(int alignment) void
setAlignmentSeparate
(int labelAlign, int lineAlign) void
setEllipsis
(boolean ellipsis) When true the text will be truncated "..." if it does not fit within the width of the label.void
setEllipsisString
(String ellipsis) When non-null the text will be truncated "..." if it does not fit within the width of the label.void
setFontScale
(float fontScale) void
setFontScaleSeparate
(float fontScaleX, float fontScaleY) void
setFontScaleX
(float fontScaleX) void
setFontScaleY
(float fontScaleY) void
setStyle
(Label.LabelStyle style) void
setText
(CharSequence newText) boolean
setTextFromInt
(int value) Sets the text to the specified integer value.void
setWrap
(boolean wrap) If false, the text will only wrap where it contains newlines (\n).boolean
textEquals
(CharSequence other) toString()
Methods inherited from class com.prineside.tdi2.scene2d.ui.Widget
getMaxHeight, getMaxHeightValue, getMaxWidth, getMaxWidthValue, getMinHeight, getMinHeightValue, getMinWidth, getMinWidthValue, getPrefHeightValue, getPrefWidthValue, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setPrefHeight, setPrefHeight, setPrefWidth, setPrefWidth, validate
Methods inherited from class com.prineside.tdi2.scene2d.Actor
act, addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, 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, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
Constructor Details
-
Label
-
-
Method Details
-
setStyle
-
getStyle
Returns the label's style. Modifying the returned style may not have an effect untilsetStyle(LabelStyle)
is called. -
setTextFromInt
public boolean setTextFromInt(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
- Parameters:
newText
- If null, "" will be used.
-
textEquals
-
getText
-
invalidate
public void invalidate()Description copied from interface:Layout
Invalidates 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:
invalidate
in interfaceLayout
- Overrides:
invalidate
in classWidget
-
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, 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
Description copied from class:Widget
If 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:
getPrefWidth
in interfaceLayout
- Overrides:
getPrefWidth
in classWidget
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeight
in interfaceLayout
- Overrides:
getPrefHeight
in classWidget
-
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:
-
setAlignmentSeparate
public void setAlignmentSeparate(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:
-
setFontScale
public void setFontScale(float fontScale) -
setFontScaleSeparate
public void setFontScaleSeparate(float fontScaleX, float fontScaleY) -
getFontScaleX
public float getFontScaleX() -
setFontScaleX
public void setFontScaleX(float fontScaleX) -
getFontScaleY
public float getFontScaleY() -
setFontScaleY
public void setFontScaleY(float fontScaleY) -
setEllipsisString
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. -
toString
-