libgdx API

com.badlogic.gdx.scenes.scene2d.ui
Class List

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
All Implemented Interfaces:
Layout

public class List
extends Widget

A list of string items.

Functionality

A list displays textual items and highlights the current selection. A List.SelectionListener can be registered with the list to listen to selection changes. Items have an index in the list, the top item having the index 0.

Layout

The (preferred) width and height of a List are derrived from the bounding box around all list items. Use #setPrefSize(int, int) to programmatically change the size to your liking. In case the width and height you set are to small for the contained text you will see artifacts. The patch highlighting the current selection will have the width of the List, either determined as explained above or set programmatically.

Style

A List is a Widget a text rendered for each list item via a BitmapFont and Color as well as a NinePatch highlighting the current selection and a second Color used for the text of the currently selected item. The highlighting NinePatch is rendered beneath the selected item. The style is defined via an instance of List.ListStyle, which can be done either programmatically or via a Skin.

A List's style definition in an XML skin file should look like this:
 <list name="styleName"
       font="fontName"
       fontColorUnselected="colorName"
       fontColorSelected="colorName" 
       selected="selectedPatch"/>
 
 

Author:
mzechner

Nested Class Summary
static class List.ListStyle
          Defines a list style, see List
static interface List.SelectionListener
          Interface for listening to selection changes.
 
Field Summary
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
invalidated
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, touchable, visible, width, x, y
 
Constructor Summary
List(java.lang.String[] items, List.ListStyle style)
           
List(java.lang.String[] items, List.ListStyle style, java.lang.String name)
          Creates a new List.
List(java.lang.String[] items, Skin skin)
           
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          Draws the Actor.
 java.lang.String[] getItems()
           
 float getPrefHeight()
           
 float getPrefWidth()
           
 int getSelectedIndex()
           
 java.lang.String getSelection()
           
 Actor hit(float x, float y)
           
 void layout()
          Positions and sizes each child of this actor.
 void setItems(java.lang.String[] items)
          Sets the items of this list.
 void setSelectedIndex(int index)
           
 void setSelection(int index)
           
 int setSelection(java.lang.String item)
           
 void setSelectionListener(List.SelectionListener listener)
          Sets the List.SelectionListener of this list.
 void setStyle(List.ListStyle style)
          Sets the style of this widget.
 boolean touchDown(float x, float y, int pointer)
           
 void touchDragged(float x, float y, int pointer)
           
 void touchUp(float x, float y, int pointer)
           
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, isMarkedToRemove, keyDown, keyTyped, keyUp, markToRemove, remove, scrolled, toLocalCoordinates, toString, touchMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

List

public List(java.lang.String[] items,
            Skin skin)

List

public List(java.lang.String[] items,
            List.ListStyle style)

List

public List(java.lang.String[] items,
            List.ListStyle style,
            java.lang.String name)
Creates a new List. The width and height is determined from the bounding box around all items.

Parameters:
items - the items
style - the List.ListStyle
name - the name
Method Detail

setStyle

public void setStyle(List.ListStyle style)
Sets the style of this widget.

Parameters:
style -

layout

public void layout()
Description copied from interface: Layout
Positions and sizes each child of this actor. Subsequent calls will not have any affect unless Layout.invalidate() is called.


draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
Description copied from class: Actor
Draws the Actor. The spriteBatch is configured so that the Actor can draw in its parents coordinate system. The parent's alpha is passed to the method in order for the Actor to multiply it with its own alpha. This will allow FadeIn and other Actions to have an effect even if they are only set on the parent of the Actor.

Specified by:
draw in class Actor
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

touchDown

public boolean touchDown(float x,
                         float y,
                         int pointer)
Specified by:
touchDown in class Actor

touchUp

public void touchUp(float x,
                    float y,
                    int pointer)
Specified by:
touchUp in class Actor

touchDragged

public void touchDragged(float x,
                         float y,
                         int pointer)
Specified by:
touchDragged in class Actor

hit

public Actor hit(float x,
                 float y)
Overrides:
hit in class Widget

getSelectedIndex

public int getSelectedIndex()
Returns:
the index of the currently selected item. The top item has an index of 0.

setSelectedIndex

public void setSelectedIndex(int index)

getSelection

public java.lang.String getSelection()
Returns:
the text of the currently selected item or null if the list is empty

setSelection

public void setSelection(int index)
Parameters:
index - sets the selected item

setSelection

public int setSelection(java.lang.String item)

setItems

public void setItems(java.lang.String[] items)
Sets the items of this list.

Parameters:
items - the items.

getItems

public java.lang.String[] getItems()

getPrefWidth

public float getPrefWidth()

getPrefHeight

public float getPrefHeight()

setSelectionListener

public void setSelectionListener(List.SelectionListener listener)
Sets the List.SelectionListener of this list.

Parameters:
listener - the listener or null

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)