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.ChangeEvent
is 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 class
List.ListStyle
The style for a list, seeList
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearItems()
void
draw(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 void
drawBackground(Batch batch, float parentAlpha)
Called to draw the background.protected GlyphLayout
drawItem(Batch batch, BitmapFont font, int index, T item, float x, float y, float width)
protected void
drawSelection(Batch batch, Drawable drawable, float x, float y, float width, float height)
int
getAlignment()
Rectangle
getCullingArea()
T
getItemAt(float y)
float
getItemHeight()
int
getItemIndexAt(float y)
Array<T>
getItems()
Returns the internal items array.InputListener
getKeyListener()
T
getOverItem()
float
getPrefHeight()
float
getPrefWidth()
T
getPressedItem()
T
getSelected()
Returns the first selected item, or null.int
getSelectedIndex()
ArraySelection<T>
getSelection()
List.ListStyle
getStyle()
Returns the list's style.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)
Sets the horizontal alignment of the list items.void
setCullingArea(Rectangle cullingArea)
void
setItems(Array newItems)
Sets the items visible in the list, clearing the selection if it is no longer valid.void
setItems(T... newItems)
void
setSelected(T item)
Sets the selection to only the passed item, if it is a possible choice.void
setSelectedIndex(int index)
Sets the selection to only the selected index.void
setSelection(ArraySelection<T> selection)
void
setStyle(List.ListStyle style)
void
setTypeToSelect(boolean typeToSelect)
java.lang.String
toString(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: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
public void draw(Batch batch, float parentAlpha)
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.
-
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:
getPrefWidth
in interfaceLayout
- Overrides:
getPrefWidth
in classWidget
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeight
in interfaceLayout
- Overrides:
getPrefHeight
in classWidget
-
toString
public java.lang.String toString(T object)
-
setCullingArea
public void setCullingArea(@Null Rectangle cullingArea)
- Specified by:
setCullingArea
in 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()
-
-