Class List<T>
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.Actor
-
- com.badlogic.gdx.scenes.scene2d.ui.Widget
-
- com.badlogic.gdx.scenes.scene2d.ui.List<T>
-
public class List<T> extends Widget implements Cullable
A list (aka list box) displays textual items and highlights the currently selected item.ChangeListener.ChangeEventis fired when the list selection changes.The preferred size of the list is determined by the text bounds of the items and the size of the
List.ListStyle.selection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classList.ListStyleThe style for a list, seeList.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearItems()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 voiddrawBackground(Batch batch, float parentAlpha)Called to draw the background.protected GlyphLayoutdrawItem(Batch batch, BitmapFont font, int index, T item, float x, float y, float width)protected voiddrawSelection(Batch batch, Drawable drawable, float x, float y, float width, float height)intgetAlignment()RectanglegetCullingArea()TgetItemAt(float y)floatgetItemHeight()intgetItemIndexAt(float y)Array<T>getItems()Returns the internal items array.InputListenergetKeyListener()TgetOverItem()floatgetPrefHeight()floatgetPrefWidth()TgetPressedItem()TgetSelected()Returns the first selected item, or null.intgetSelectedIndex()ArraySelection<T>getSelection()List.ListStylegetStyle()Returns the list's style.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)Sets the horizontal alignment of the list items.voidsetCullingArea(Rectangle cullingArea)voidsetItems(Array newItems)Sets the items visible in the list, clearing the selection if it is no longer valid.voidsetItems(T... newItems)voidsetSelected(T item)Sets the selection to only the passed item, if it is a possible choice.voidsetSelectedIndex(int index)Sets the selection to only the selected index.voidsetSelection(ArraySelection<T> selection)voidsetStyle(List.ListStyle style)voidsetTypeToSelect(boolean typeToSelect)java.lang.StringtoString(T object)-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, 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, toString
-
-
-
-
Constructor Detail
-
List
public List(Skin skin)
-
List
public List(Skin skin, java.lang.String styleName)
-
List
public List(List.ListStyle style)
-
-
Method Detail
-
setStyle
public void setStyle(List.ListStyle style)
-
getStyle
public List.ListStyle getStyle()
Returns the list's style. Modifying the returned style may not have an effect untilsetStyle(ListStyle)is called.
-
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.
-
drawSelection
protected void drawSelection(Batch batch, @Null Drawable drawable, float x, float y, float width, float height)
-
drawBackground
protected void drawBackground(Batch batch, float parentAlpha)
Called to draw the background. Default implementation draws the style background drawable.
-
drawItem
protected GlyphLayout drawItem(Batch batch, BitmapFont font, int index, T item, float x, float y, float width)
-
getSelection
public ArraySelection<T> getSelection()
-
setSelection
public void setSelection(ArraySelection<T> selection)
-
setSelected
public void setSelected(@Null T item)
Sets the selection to only the passed item, if it is a possible choice.- Parameters:
item- May be null.
-
getSelectedIndex
public int getSelectedIndex()
- Returns:
- The index of the first selected item. The top item has an index of 0. Nothing selected has an index of -1.
-
setSelectedIndex
public void setSelectedIndex(int index)
Sets the selection to only the selected index.- Parameters:
index- -1 to clear the selection.
-
getOverItem
public T getOverItem()
- Returns:
- May be null.
-
getPressedItem
public T getPressedItem()
- Returns:
- May be null.
-
getItemIndexAt
public int getItemIndexAt(float y)
- Returns:
- -1 if not over an item.
-
setItems
public void setItems(T... newItems)
-
setItems
public void setItems(Array newItems)
Sets the items visible in the list, clearing the selection if it is no longer valid. If a selection isSelection.getRequired(), the first item is selected. This can safely be called with a (modified) array returned fromgetItems().
-
clearItems
public void clearItems()
-
getItems
public Array<T> getItems()
Returns the internal items array. If modified,setItems(Array)must be called to reflect the changes.
-
getItemHeight
public float getItemHeight()
-
getPrefWidth
public float getPrefWidth()
- Specified by:
getPrefWidthin interfaceLayout- Overrides:
getPrefWidthin classWidget
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeightin interfaceLayout- Overrides:
getPrefHeightin classWidget
-
toString
public java.lang.String toString(T object)
-
setCullingArea
public void setCullingArea(@Null Rectangle cullingArea)
- Specified by:
setCullingAreain interfaceCullable- Parameters:
cullingArea- The culling area in the child actor's coordinates.
-
getCullingArea
public Rectangle getCullingArea()
- Returns:
- May be null.
- See Also:
setCullingArea(Rectangle)
-
setAlignment
public void setAlignment(int alignment)
Sets the horizontal alignment of the list items.- Parameters:
alignment- SeeAlign.
-
getAlignment
public int getAlignment()
-
setTypeToSelect
public void setTypeToSelect(boolean typeToSelect)
-
getKeyListener
public InputListener getKeyListener()
-
-