Package arc.scene.ui
Class Label
java.lang.Object
arc.scene.Element
arc.scene.ui.Label
- Direct Known Subclasses:
FLabel
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.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected FontCache
protected String
protected boolean
protected float
protected float
protected int
protected float
protected final GlyphLayout
protected int
protected final Vec2
protected boolean
protected static final GlyphLayout
protected Label.LabelStyle
protected static final Color
protected final StringBuilder
protected boolean
Fields inherited from class arc.scene.Element
color, cullable, fillParent, height, name, originX, originY, parent, parentAlpha, rotation, scaleX, scaleY, touchable, touchablility, translation, userObject, visibility, visible, width, x, y
-
Constructor Summary
ConstructorDescriptionLabel
(Prov<CharSequence> sup) Label
(CharSequence text) Label
(CharSequence text, Label.LabelStyle style) -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw()
Draws the element.Allows subclasses to access the cache.float
float
int
int
float
float
getStyle()
Returns the label's style.getText()
void
Invalidates this actor's layout, causingElement.layout()
to happen the next timeElement.validate()
is called.void
layout()
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsElement.invalidate()
on any each child whose width or height has changed, and callsElement.validate()
on each child.void
setAlignment
(int alignment) void
setAlignment
(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
setEllipsis
(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
setFontScale
(float fontScaleX, float fontScaleY) void
setFontScaleX
(float fontScaleX) void
setFontScaleY
(float fontScaleY) void
setStyle
(Label.LabelStyle style) void
setText
(Prov<CharSequence> sup) void
setText
(CharSequence newText) 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 arc.scene.Element
act, actions, addAction, addCaptureListener, addListener, change, changed, clear, clearActions, clearListeners, clicked, clicked, clicked, clicked, clipBegin, clipBegin, clipEnd, dragged, exited, fire, fireClick, getActions, getCaptureListeners, getHeight, getListeners, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getRight, getRotation, getScene, getTop, getWidth, getX, getY, getZIndex, hasActions, hasKeyboard, hasMouse, hasParent, hasScroll, hit, hovered, invalidateHierarchy, isAscendantOf, isDescendantOf, isDescendantOf, isTouchable, keepInStage, keyDown, keyDown, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, needsLayout, notify, pack, parentToLocalCoordinates, released, remove, removeAction, removeCaptureListener, removeListener, requestKeyboard, requestScroll, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, scrolled, setBounds, setColor, setColor, setFillParent, setHeight, setLayoutEnabled, setOrigin, setOrigin, setPosition, setPosition, setRotation, setRotationOrigin, setScale, setScale, setScene, setSize, setSize, setTranslation, setWidth, setZIndex, sizeBy, sizeBy, sizeChanged, stageToLocalCoordinates, tapped, toBack, toFront, touchable, update, updateVisibility, validate, visible
-
Field Details
-
tempColor
-
prefSizeLayout
-
layout
-
prefSize
-
text
-
style
-
cache
-
labelAlign
protected int labelAlign -
lineAlign
protected int lineAlign -
wrap
protected boolean wrap -
lastPrefHeight
protected float lastPrefHeight -
prefSizeInvalid
protected boolean prefSizeInvalid -
fontScaleX
protected float fontScaleX -
fontScaleY
protected float fontScaleY -
fontScaleChanged
protected boolean fontScaleChanged -
ellipsis
-
-
Constructor Details
-
Label
-
Label
-
Label
-
-
Method Details
-
getStyle
Returns the label's style. Modifying the returned style may not have an effect untilsetStyle(LabelStyle)
is called. -
setStyle
-
setText
-
textEquals
-
getText
-
setText
- Parameters:
newText
- May be null, "" will be used. If this text starts with '$' or '@', this label will look inCore.bundle
for matching text.
-
invalidate
public void invalidate()Description copied from class:Element
Invalidates this actor's layout, causingElement.layout()
to happen the next timeElement.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).- Overrides:
invalidate
in classElement
-
layout
public void layout()Description copied from class:Element
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsElement.invalidate()
on any each child whose width or height has changed, and callsElement.validate()
on each child. This method should almost never be called directly, insteadElement.validate()
should be used. -
draw
public void draw()Description copied from class:Element
Draws the element. Does nothing by default. -
getPrefWidth
public float getPrefWidth()- Overrides:
getPrefWidth
in classElement
-
getPrefHeight
public float getPrefHeight()- Overrides:
getPrefHeight
in classElement
-
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.
-
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:
-
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:
-
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
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. -
getFontCache
Allows subclasses to access the cache. -
toString
-