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.
public class Tree<N extends Tree.Node,V> extends WidgetGroup
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.ChangeEventis fired when the selected node changes.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(N node)voidclearChildren(boolean unfocus)Removes all tree nodes.voidcollapseAll()voiddraw(Batch batch, float parentAlpha)If this method is overridden, the super method orWidgetGroup.validate()should be called to ensure the widget group is laid out.protected voiddrawBackground(Batch batch, float parentAlpha)Called to draw the background.protected voiddrawExpandIcon(N node, Drawable expandIcon, Batch batch, float x, float y)protected voiddrawIcon(N node, Drawable icon, Batch batch, float x, float y)protected floatdrawIcons(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 voiddrawOver(N node, Drawable over, Batch batch, float x, float y, float width, float height)protected voiddrawSelection(N node, Drawable selection, Batch batch, float x, float y, float width, float height)voidexpandAll()voidfindExpandedValues(Array<V> values)NfindNode(V value)Returns the node with the specified value, or null.ClickListenergetClickListener()Returns the click listener the tree uses for clicking on nodes and the over node.protected DrawablegetExpandIcon(N node, float iconX)Returns the drawable for the expand icon.floatgetIndentSpacing()Returns the amount of horizontal space for indentation level.NgetNodeAt(float y)Array<N>getNodes()Deprecated.UsegetRootNodes().NgetOverNode()VgetOverValue()floatgetPrefHeight()floatgetPrefWidth()Array<N>getRootNodes()If the order of the root nodes is changed,updateRootNodes()must be called to ensure the nodes' actors are in the correct order.NgetSelectedNode()Returns the first selected node, or null.VgetSelectedValue()Returns the first selected value, or null.Selection<N>getSelection()Tree.TreeStylegetStyle()floatgetYSpacing()voidinsert(int index, N node)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.voidremove(N node)voidrestoreExpandedValues(Array<V> values)voidsetIconSpacing(float left, float right)Sets the amount of horizontal space left and right of the node's icon.voidsetIndentSpacing(float indentSpacing)voidsetOverNode(N overNode)voidsetPadding(float padding)Sets the amount of horizontal space between the nodes and the left/right edges of the tree.voidsetPadding(float left, float right)Sets the amount of horizontal space between the nodes and the left/right edges of the tree.voidsetStyle(Tree.TreeStyle style)voidsetYSpacing(float ySpacing)Sets the amount of vertical space between nodes.voidupdateRootNodes()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 Detail
-
Tree
public Tree(Skin skin)
-
Tree
public Tree(Skin skin, java.lang.String styleName)
-
Tree
public Tree(Tree.TreeStyle style)
-
-
Method Detail
-
setStyle
public void setStyle(Tree.TreeStyle style)
-
add
public void add(N node)
-
insert
public void insert(int index, N node)
-
remove
public void remove(N node)
-
clearChildren
public void clearChildren(boolean unfocus)
Removes all tree nodes.- Overrides:
clearChildrenin classGroup
-
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 classWidgetGroup
-
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.- Specified by:
layoutin interfaceLayout- Overrides:
layoutin classWidgetGroup
-
draw
public void draw(Batch batch, float parentAlpha)
Description copied from class:WidgetGroupIf this method is overridden, the super method orWidgetGroup.validate()should be called to ensure the widget group is laid out.- Overrides:
drawin classWidgetGroupparentAlpha- The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
-
drawBackground
protected void drawBackground(Batch batch, float parentAlpha)
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
protected void drawSelection(N node, Drawable selection, Batch batch, float x, float y, float width, float height)
-
drawOver
protected void drawOver(N node, Drawable over, Batch batch, float x, float y, float width, float height)
-
drawExpandIcon
protected void drawExpandIcon(N node, Drawable expandIcon, Batch batch, float x, float y)
-
getExpandIcon
protected Drawable getExpandIcon(N node, float iconX)
Returns the drawable for the expand icon. The default implementation returnsTree.TreeStyle.plusOverorTree.TreeStyle.minusOveron 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.
-
getStyle
public Tree.TreeStyle getStyle()
-
getRootNodes
public Array<N> 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 public Array<N> 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:
Tree.Node.updateChildren()
-
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:
getPrefWidthin interfaceLayout- Overrides:
getPrefWidthin classWidgetGroup
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeightin interfaceLayout- Overrides:
getPrefHeightin classWidgetGroup
-
collapseAll
public void collapseAll()
-
expandAll
public void expandAll()
-
getClickListener
public ClickListener getClickListener()
Returns the click listener the tree uses for clicking on nodes and the over node.
-
-