public class List<T> extends Widget implements Cullable
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
.
Modifier and Type | Class and Description |
---|---|
static class |
List.ListStyle
The style for a list, see
List . |
Constructor and Description |
---|
List(List.ListStyle style) |
List(Skin skin) |
List(Skin skin,
java.lang.String styleName) |
Modifier and Type | Method and Description |
---|---|
void |
clearItems() |
void |
draw(Batch batch,
float parentAlpha)
If this method is overridden, the super method or
Widget.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,
calls
Layout.invalidate() on any each child whose width or height has changed, and calls Layout.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) |
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
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
public List(Skin skin)
public List(Skin skin, java.lang.String styleName)
public List(List.ListStyle style)
public void setStyle(List.ListStyle style)
public List.ListStyle getStyle()
setStyle(ListStyle)
is
called.public void layout()
Layout
Layout.invalidate()
on any each child whose width or height has changed, and calls Layout.validate()
on each
child. This method should almost never be called directly, instead Layout.validate()
should be used.public void draw(Batch batch, float parentAlpha)
Widget
Widget.validate()
should be called to ensure the widget is laid out.protected void drawSelection(Batch batch, @Null Drawable drawable, float x, float y, float width, float height)
protected void drawBackground(Batch batch, float parentAlpha)
protected GlyphLayout drawItem(Batch batch, BitmapFont font, int index, T item, float x, float y, float width)
public ArraySelection<T> getSelection()
public void setSelection(ArraySelection<T> selection)
public void setSelected(@Null T item)
item
- May be null.public int getSelectedIndex()
public void setSelectedIndex(int index)
index
- -1 to clear the selection.public T getOverItem()
public T getPressedItem()
public int getItemIndexAt(float y)
public void setItems(T... newItems)
public void setItems(Array newItems)
Selection.getRequired()
, the first item is selected. This can safely be called with a (modified) array returned
from getItems()
.public void clearItems()
public Array<T> getItems()
setItems(Array)
must be called to reflect the changes.public float getItemHeight()
public float getPrefWidth()
getPrefWidth
in interface Layout
getPrefWidth
in class Widget
public float getPrefHeight()
getPrefHeight
in interface Layout
getPrefHeight
in class Widget
public java.lang.String toString(T object)
public void setCullingArea(@Null Rectangle cullingArea)
setCullingArea
in interface Cullable
cullingArea
- The culling area in the child actor's coordinates.public Rectangle getCullingArea()
setCullingArea(Rectangle)
public void setAlignment(int alignment)
alignment
- See Align
.public int getAlignment()
public void setTypeToSelect(boolean typeToSelect)
public InputListener getKeyListener()