Class Tree<N extends Tree.Node,V>
java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.Group
com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
com.badlogic.gdx.scenes.scene2d.ui.Tree<N,V>
- Type Parameters:
N
- The type of nodes in the tree.V
- The type of values for each node.
- All Implemented Interfaces:
Styleable<Tree.TreeStyle>
,Cullable
,Layout
A tree widget where each node has an icon, actor, and child nodes.
The preferred size of the tree is determined by the preferred size of the actors for the expanded nodes.
ChangeListener.ChangeEvent
is fired when the selected node changes.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
clearChildren
(boolean unfocus) Removes all tree nodes.void
void
If this method is overridden, the super method orWidgetGroup.validate()
should be called to ensure the widget group is laid out.protected void
drawBackground
(Batch batch, float parentAlpha) Called to draw the background.protected void
drawExpandIcon
(N node, Drawable expandIcon, Batch batch, float x, float y) protected void
protected float
drawIcons
(Batch batch, float r, float g, float b, float a, N parent, Array<N> nodes, float indent, float plusMinusWidth) Draws selection, icons, and expand icons.protected void
protected void
drawSelection
(N node, Drawable selection, Batch batch, float x, float y, float width, float height) void
void
findExpandedValues
(Array<V> values) Returns the node with the specified value, or null.Returns the click listener the tree uses for clicking on nodes and the over node.protected Drawable
getExpandIcon
(N node, float iconX) Returns the drawable for the expand icon.float
Returns the amount of horizontal space for indentation level.getNodeAt
(float y) getNodes()
Deprecated.float
float
If the order of the root nodes is changed,updateRootNodes()
must be called to ensure the nodes' actors are in the correct order.Returns the first selected node, or null.Returns the first selected value, or null.getStyle()
Get the current style of the actorfloat
void
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
void
restoreExpandedValues
(Array<V> values) void
setIconSpacing
(float left, float right) Sets the amount of horizontal space left and right of the node's icon.void
setIndentSpacing
(float indentSpacing) void
setOverNode
(N overNode) void
setPadding
(float padding) Sets the amount of horizontal space between the nodes and the left/right edges of the tree.void
setPadding
(float left, float right) Sets the amount of horizontal space between the nodes and the left/right edges of the tree.void
setStyle
(Tree.TreeStyle style) Set the current style of the actorvoid
setYSpacing
(float ySpacing) Sets the amount of vertical space between nodes.void
Updates the order of the actors in the tree for all root nodes and all child nodes.Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
childrenChanged, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, hit, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group
act, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, clear, clearChildren, computeTransform, debugAll, drawChildren, drawDebug, drawDebugChildren, findActor, getChild, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, removeActor, removeActor, removeActorAt, resetTransform, resetTransform, setCullingArea, setDebug, setStage, setTransform, swapActor, swapActor, toString
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, 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, 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, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
Constructor Details
-
Tree
-
Tree
-
Tree
-
-
Method Details
-
setStyle
Description copied from interface:Styleable
Set the current style of the actor -
add
-
insert
-
remove
-
clearChildren
public void clearChildren(boolean unfocus) Removes all tree nodes.- Overrides:
clearChildren
in classGroup
-
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 classWidgetGroup
-
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.- Specified by:
layout
in interfaceLayout
- Overrides:
layout
in classWidgetGroup
-
draw
Description copied from class:WidgetGroup
If this method is overridden, the super method orWidgetGroup.validate()
should be called to ensure the widget group is laid out.- Overrides:
draw
in classWidgetGroup
parentAlpha
- The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
-
drawBackground
Called to draw the background. Default implementation draws the style background drawable. -
drawIcons
protected float drawIcons(Batch batch, float r, float g, float b, float a, @Null N parent, Array<N> nodes, float indent, float plusMinusWidth) Draws selection, icons, and expand icons.- Parameters:
parent
- null for the root nodes.- Returns:
- The Y position of the last visible actor for the nodes.
-
drawSelection
-
drawOver
-
drawExpandIcon
-
drawIcon
-
getExpandIcon
Returns the drawable for the expand icon. The default implementation returnsTree.TreeStyle.plusOver
orTree.TreeStyle.minusOver
on the desktop if the node is theover node
, the mouse is left oficonX
, and clicking would expand the node.- Parameters:
iconX
- The X coordinate of the over node's icon.
-
getNodeAt
- Returns:
- May be null.
-
getSelection
-
getSelectedNode
Returns the first selected node, or null. -
getSelectedValue
Returns the first selected value, or null. -
getStyle
Description copied from interface:Styleable
Get the current style of the actor -
getRootNodes
If the order of the root nodes is changed,updateRootNodes()
must be called to ensure the nodes' actors are in the correct order. -
getNodes
Deprecated.UsegetRootNodes()
. -
updateRootNodes
public void updateRootNodes()Updates the order of the actors in the tree for all root nodes and all child nodes. This is useful after changing the order ofgetRootNodes()
.- See Also:
-
getOverNode
- Returns:
- May be null.
-
getOverValue
- Returns:
- May be null.
-
setOverNode
- Parameters:
overNode
- May be null.
-
setPadding
public void setPadding(float padding) Sets the amount of horizontal space between the nodes and the left/right edges of the tree. -
setPadding
public void setPadding(float left, float right) Sets the amount of horizontal space between the nodes and the left/right edges of the tree. -
setIndentSpacing
public void setIndentSpacing(float indentSpacing) -
getIndentSpacing
public float getIndentSpacing()Returns the amount of horizontal space for indentation level. -
setYSpacing
public void setYSpacing(float ySpacing) Sets the amount of vertical space between nodes. -
getYSpacing
public float getYSpacing() -
setIconSpacing
public void setIconSpacing(float left, float right) Sets the amount of horizontal space left and right of the node's icon. If a node has no icon, the left spacing is used between the plus/minus drawable and the node's actor. -
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidth
in interfaceLayout
- Overrides:
getPrefWidth
in classWidgetGroup
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeight
in interfaceLayout
- Overrides:
getPrefHeight
in classWidgetGroup
-
findExpandedValues
-
restoreExpandedValues
-
findNode
Returns the node with the specified value, or null. -
collapseAll
public void collapseAll() -
expandAll
public void expandAll() -
getClickListener
Returns the click listener the tree uses for clicking on nodes and the over node.
-
getRootNodes()
.