com.badlogic.gdx.scenes.scene2d.ui
Class List<T>

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.ui.Widget
          extended by com.badlogic.gdx.scenes.scene2d.ui.List<T>
All Implemented Interfaces:
Cullable, Layout

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.

Author:
mzechner, Nathan Sweet

Nested Class Summary
static class List.ListStyle
          The style for a list, see List.
 
Constructor Summary
List(List.ListStyle style)
           
List(Skin skin)
           
List(Skin skin, String styleName)
           
 
Method Summary
 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.
 float getItemHeight()
           
 Array<T> getItems()
           
 float getPrefHeight()
           
 float getPrefWidth()
           
 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() any each child whose width or height has changed, and calls Layout.validate() on each child.
 void setCullingArea(Rectangle cullingArea)
           
 void setItems(Array newItems)
          Sets the current items, clearing the selection if it is no longer valid.
 void setItems(T... newItems)
           
 void setSelectedIndex(int index)
          Sets the selection to only the selected index.
 void setStyle(List.ListStyle style)
           
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, addAction, addCaptureListener, addListener, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getY, getZIndex, hasParent, hit, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

List

public List(Skin skin)

List

public List(Skin skin,
            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 until setStyle(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, calls Layout.invalidate() 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.

Specified by:
layout in interface Layout
Overrides:
layout in class Widget

draw

public void draw(Batch batch,
                 float parentAlpha)
Description copied from class: Widget
If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.

Overrides:
draw in class Widget
parentAlpha - Should be multiplied with the actor's alpha, allowing a parent's alpha to affect all children.

getSelection

public ArraySelection<T> getSelection()

getSelected

public T getSelected()
Returns the first selected item, or 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.


setItems

public void setItems(T... newItems)

setItems

public void setItems(Array newItems)
Sets the current items, clearing the selection if it is no longer valid. If a selection is Selection.getRequired(), the first item is selected.


getItems

public Array<T> getItems()

getItemHeight

public float getItemHeight()

getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout
Overrides:
getPrefWidth in class Widget

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout
Overrides:
getPrefHeight in class Widget

setCullingArea

public void setCullingArea(Rectangle cullingArea)
Specified by:
setCullingArea in interface Cullable
Parameters:
cullingArea - The culling area in the child actor's coordinates.


Copyright © 2014. All Rights Reserved.