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 entries.

Functionality

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

Layout

The (preferred) width and height of a List are derrived from the bounding box around all list entries. Use Widget.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 entry 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 entry. The highlighting NinePatch is rendered beneath the selected entry. 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
prefHeight, prefWidth
 
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[] entries, List.ListStyle style)
           
List(java.lang.String[] entries, Skin skin)
           
List(java.lang.String name, java.lang.String[] entries, List.ListStyle style)
          Creates a new List.
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          Draws the Actor.
 java.lang.String[] getEntries()
           
 int getSelectedIndex()
           
 java.lang.String getSelection()
           
 Actor hit(float x, float y)
           
 void layout()
          Positions and sizes each child of this actor.
 void setEntries(java.lang.String[] entries)
          Sets the entries of this list.
 void setSelectedIndex(int index)
           
 void setSelection(int index)
           
 int setSelection(java.lang.String entry)
           
 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
getPrefHeight, getPrefWidth, invalidate, invalidateHierarchy, setPrefSize
 
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[] entries,
            Skin skin)

List

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

List

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

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

setStyle

public void setStyle(List.ListStyle style)
Sets the style of this widget. Calls Widget.invalidateHierarchy() internally.

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 entry. The top entry has an index of 0.

setSelectedIndex

public void setSelectedIndex(int index)

getSelection

public java.lang.String getSelection()
Returns:
the text of the currently selected entry 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 entry)

setEntries

public void setEntries(java.lang.String[] entries)
Sets the entries of this list. Invalidates all parents.

Parameters:
entries - the entries.

getEntries

public java.lang.String[] getEntries()

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)