APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.ui

public Class List<T>

extends Widget
implements Cullable, Styleable<List.ListStyle>
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.ui.Styleable, com.badlogic.gdx.scenes.scene2d.utils.Cullable
Imports
com.badlogic.gdx.Input.Keys, com.badlogic.gdx.graphics.Color, com.badlogic.gdx.graphics.g2d.Batch, .BitmapFont, .GlyphLayout, com.badlogic.gdx.math.Rectangle, com.badlogic.gdx.scenes.scene2d.Actor, .InputEvent, .InputListener, com.badlogic.gdx.scenes.scene2d.utils.ArraySelection, .ChangeListener.ChangeEvent, .Cullable, .Drawable, .UIUtils, com.badlogic.gdx.utils.Align, .Array, .Null, .ObjectSet, .Pool

A list (aka list box) displays textual items and highlights the currently selected item.

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 ListStyle#selection.

Authors
mzechner, Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
List.ListStyle

The style for a list, see List.

Field Summary

Modifier and TypeField and Description
private int
private Rectangle
pack-priv float
pack-priv final Array<T>
private InputListener
pack-priv int
private float
private float
pack-priv int
pack-priv ArraySelection<T>
pack-priv List.ListStyle
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
List(Skin skin)

public
List(Skin skin, String styleName)

public

Method Summary

Modifier and TypeMethod and Description
public void
public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or 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)

public int
public Rectangle
getCullingArea()

Returns: May be null.

public T
getItemAt(float y)

Returns: null if not over an item.

public float
public int
getItemIndexAt(float y)

Returns: -1 if not over an item.

public Array<T>
getItems()

Returns the internal items array.

public InputListener
public T
getOverItem()

Returns: May be null.

public float
public float
public T
getPressedItem()

Returns: May be null.

public T
getSelected()

Returns the first selected item, or null.

public int
getSelectedIndex()

Returns: The index of the first selected item.

public ArraySelection<T>
public List.ListStyle
getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the list's style.

public void
layout()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.layout.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child.

public void
setAlignment(int
See Align.
alignment
)

Sets the horizontal alignment of the list items.

public void
public void
setItems(T... newItems)

public void
setItems(Array<T> newItems)

Sets the items visible in the list, clearing the selection if it is no longer valid.

public void
setSelected(T
May be null.
item
)

Sets the selection to only the passed item, if it is a possible choice.

public void
setSelectedIndex(int
-1 to clear the selection.
index
)

Sets the selection to only the selected index.

public void
public void
setStyle(List.ListStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

public void
setTypeToSelect(boolean typeToSelect)

public String
toString(T object)

Inherited from com.badlogic.gdx.scenes.scene2d.ui.Widget:
getMaxHeightgetMaxWidthgetMinHeightgetMinWidthinvalidateinvalidateHierarchyneedsLayoutpacksetFillParentsetLayoutEnabledsizeChangedvalidate

Field Detail

alignmentback to summary
private int alignment
cullingAreaback to summary
private Rectangle cullingArea
itemHeightback to summary
pack-priv float itemHeight
itemsback to summary
pack-priv final Array<T> items
keyListenerback to summary
private InputListener keyListener
overIndexback to summary
pack-priv int overIndex
prefHeightback to summary
private float prefHeight
prefWidthback to summary
private float prefWidth
pressedIndexback to summary
pack-priv int pressedIndex
selectionback to summary
pack-priv ArraySelection<T> selection
styleback to summary
pack-priv List.ListStyle style
typeToSelectback to summary
pack-priv boolean typeToSelect

Constructor Detail

Listback to summary
public List(Skin skin)
Listback to summary
public List(Skin skin, String styleName)
Listback to summary
public List(List.ListStyle style)

Method Detail

clearItemsback to summary
public void clearItems()
drawback to summary
public void draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

drawBackgroundback to summary
protected void drawBackground(Batch batch, float parentAlpha)

Called to draw the background. Default implementation draws the style background drawable.

drawItemback to summary
protected GlyphLayout drawItem(Batch batch, BitmapFont font, int index, T item, float x, float y, float width)
drawSelectionback to summary
protected void drawSelection(Batch batch, Drawable drawable, float x, float y, float width, float height)
getAlignmentback to summary
public int getAlignment()
getCullingAreaback to summary
public Rectangle getCullingArea()
Returns:Rectangle

May be null.

See Also
setCullingArea(Rectangle)
getItemAtback to summary
public T getItemAt(float y)
Returns:T

null if not over an item.

Annotations
@Null
getItemHeightback to summary
public float getItemHeight()
getItemIndexAtback to summary
public int getItemIndexAt(float y)
Returns:int

-1 if not over an item.

getItemsback to summary
public Array<T> getItems()

Returns the internal items array. If modified, setItems(Array) must be called to reflect the changes.

getKeyListenerback to summary
public InputListener getKeyListener()
getOverItemback to summary
public T getOverItem()
Returns:T

May be null.

getPrefHeightback to summary
public float getPrefHeight()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefHeight.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefHeight.

getPrefWidthback to summary
public float getPrefWidth()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefWidth.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefWidth.

getPressedItemback to summary
public T getPressedItem()
Returns:T

May be null.

getSelectedback to summary
public T getSelected()

Returns the first selected item, or null.

Annotations
@Null
getSelectedIndexback to summary
public int getSelectedIndex()
Returns:int

The index of the first selected item. The top item has an index of 0. Nothing selected has an index of -1.

getSelectionback to summary
public ArraySelection<T> getSelection()
getStyleback to summary
public List.ListStyle getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the list's style. Modifying the returned style may not have an effect until setStyle(ListStyle) is called.

layoutback to summary
public void layout()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.layout.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Doc from com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child. This method should almost never be called directly, instead validate() should be used.

setAlignmentback to summary
public void setAlignment(int alignment)

Sets the horizontal alignment of the list items.

Parameters
alignment:int

See Align.

setCullingAreaback to summary
public void setCullingArea(Rectangle cullingArea)

Implements com.badlogic.gdx.scenes.scene2d.utils.Cullable.setCullingArea.

setItemsback to summary
public void setItems(T... newItems)
setItemsback to summary
public void setItems(Array<T> newItems)

Sets the items visible in the list, clearing the selection if it is no longer valid. If a selection is ArraySelection#getRequired(), the first item is selected. This can safely be called with a (modified) array returned from getItems().

setSelectedback to summary
public void setSelected(T item)

Sets the selection to only the passed item, if it is a possible choice.

Parameters
item:T

May be null.

setSelectedIndexback to summary
public void setSelectedIndex(int index)

Sets the selection to only the selected index.

Parameters
index:int

-1 to clear the selection.

setSelectionback to summary
public void setSelection(ArraySelection<T> selection)
setStyleback to summary
public void setStyle(List.ListStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

setTypeToSelectback to summary
public void setTypeToSelect(boolean typeToSelect)
toStringback to summary
public String toString(T object)
com.badlogic.gdx.scenes.scene2d.ui back to summary

public Class List.ListStyle

extends Object
Class Inheritance

The style for a list, see List.
Authors
mzechner, Nathan Sweet

Field Summary

Modifier and TypeField and Description
public Drawable
public Drawable
public BitmapFont
public Color
public Color
public Drawable
public Drawable

Constructor Summary

AccessConstructor and Description
public
public
ListStyle(BitmapFont font, Color fontColorSelected, Color fontColorUnselected, Drawable selection)

public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backgroundback to summary
public Drawable background
Annotations
@Null
downback to summary
public Drawable down
Annotations
@Null
fontback to summary
public BitmapFont font
fontColorSelectedback to summary
public Color fontColorSelected
fontColorUnselectedback to summary
public Color fontColorUnselected
overback to summary
public Drawable over
Annotations
@Null
selectionback to summary
public Drawable selection

Constructor Detail

ListStyleback to summary
public ListStyle()
ListStyleback to summary
public ListStyle(BitmapFont font, Color fontColorSelected, Color fontColorUnselected, Drawable selection)
ListStyleback to summary
public ListStyle(List.ListStyle style)