|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.badlogic.gdx.scenes.scene2d.ui.List
public class List
A list of string items.
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.
#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.
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"/>
name
attribute defines the name of the style which you can later use with
Skin#newList(String, String[], String)
.fontName
attribute references a BitmapFont
by name, to be used for render the itemsfontColorUnselected
attribute references a Color
by name, to be used for render unselected itemsfontColorSelected
attribute references a Color
by name, to be used to render the selected itemselected
attribute references a NinePatch
by name, to be used to render the highlight behind the
selected item
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 |
---|
public List(java.lang.String[] items, Skin skin)
public List(java.lang.String[] items, List.ListStyle style)
public List(java.lang.String[] items, List.ListStyle style, java.lang.String name)
items
- the itemsstyle
- the List.ListStyle
name
- the nameMethod Detail |
---|
public void setStyle(List.ListStyle style)
style
- public void layout()
Layout
Layout.invalidate()
is
called.
public void draw(SpriteBatch batch, float parentAlpha)
Actor
FadeIn
and
other Actions to have an effect even if they are only set on the parent of the Actor.
draw
in class Actor
batch
- the spritebatch to render withparentAlpha
- the parent's alpha value.public boolean touchDown(float x, float y, int pointer)
touchDown
in class Actor
public void touchUp(float x, float y, int pointer)
touchUp
in class Actor
public void touchDragged(float x, float y, int pointer)
touchDragged
in class Actor
public Actor hit(float x, float y)
hit
in class Widget
public int getSelectedIndex()
public void setSelectedIndex(int index)
public java.lang.String getSelection()
public void setSelection(int index)
index
- sets the selected itempublic int setSelection(java.lang.String item)
public void setItems(java.lang.String[] items)
items
- the items.public java.lang.String[] getItems()
public float getPrefWidth()
public float getPrefHeight()
public void setSelectionListener(List.SelectionListener listener)
List.SelectionListener
of this list.
listener
- the listener or null
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |