|
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.ComboBox
public class ComboBox
A dropdown or combo box.
ComboBox.SelectionListener
can be registered with the ComboBox to receive notification of selection changes.
NinePatch
as well as the bounding box of the widest entry in the list of strings. Use
Widget.setPrefSize(int, int)
to change this size programmatically. In case the set size is to small to contain the
widest entry, artifacts may appear.
The additional popup list will be positioned at the bottom edge of the ComboBox, displaying all entries. The width and size is
governed by the background NinePatch
of the popup list as well as the bounding box around the list entries.
Widget
displaying a background NinePatch
as well as the selected list entry as a
label via a BitmapFont
and a corresponding Color
. Additionally a popup menu might be displayed, using a
NinePatch
for the background, another NinePatch
for highlighting the current selection and the same
BitmapFont
and Color used to display the selected entry in the actual ComboBox.
The style is defined via an instance of the ComboBox.ComboBoxStyle
class, which can be either done programmatically or via a
Skin
.
A ComboBox's style definition in a skin XML file should look like this:
<combobox name="styleName"
background="backgroundNinePatch"
listBackground="popupBackgroundNinePatch"
listSelection="popupSelectionNinePatch"
font="fontName"
fontColor="colorName" />
name
attribute defines the name of the style which you can later use with
Skin#newComboBox(String, String[], Stage, String)
.background
attribute references a NinePatch
by name, to be used as the ComboBox's backgroundlistBackground
attribute references a NinePatch
by name, to be used as the background for the
popup listlistSelection
attribute references a NinePatch
by name, to be used for highlighting a selection in
the popup listfont
attribute references a BitmapFont
by name, to be used to render the list entriesfontColor
attribute references a Color
by name, to be used to render the list entries
Nested Class Summary | |
---|---|
static class |
ComboBox.ComboBoxStyle
Defines the style of a combo box. |
protected class |
ComboBox.ComboList
|
static interface |
ComboBox.SelectionListener
Interface for listening to selection events. |
Field Summary |
---|
Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget |
---|
invalidated, 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 | |
---|---|
ComboBox(java.lang.String[] entries,
Stage stage,
ComboBox.ComboBoxStyle style)
|
|
ComboBox(java.lang.String[] entries,
Stage stage,
Skin skin)
|
|
ComboBox(java.lang.String name,
java.lang.String[] entries,
Stage stage,
ComboBox.ComboBoxStyle style)
Creates a new combo box. |
Method Summary | |
---|---|
void |
draw(SpriteBatch batch,
float parentAlpha)
Draws the Actor. |
java.lang.String |
getSelection()
|
int |
getSelectionIndex()
|
void |
layout()
Positions and sizes each child of this actor. |
void |
setEntries(java.lang.String[] entries)
Sets the entries of this combo box. |
void |
setSelection(int selection)
Sets the selected item via it's index |
void |
setSelectionListener(ComboBox.SelectionListener listener)
Sets the ComboBox.SelectionListener . |
void |
setStyle(ComboBox.ComboBoxStyle 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, hit, 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 |
---|
public ComboBox(java.lang.String[] entries, Stage stage, Skin skin)
public ComboBox(java.lang.String[] entries, Stage stage, ComboBox.ComboBoxStyle style)
public ComboBox(java.lang.String name, java.lang.String[] entries, Stage stage, ComboBox.ComboBoxStyle style)
name
- the nameentries
- the single-line entriesstage
- the stage, used for the popupstyle
- the ComboBox.ComboBoxStyle
Method Detail |
---|
public void setStyle(ComboBox.ComboBoxStyle style)
Widget.invalidateHierarchy()
internally.
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 void setSelectionListener(ComboBox.SelectionListener listener)
ComboBox.SelectionListener
.
listener
- the listener or nullpublic void setSelection(int selection)
selection
- the selection indexpublic int getSelectionIndex()
public java.lang.String getSelection()
public void setEntries(java.lang.String[] entries)
entries
- the entries
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |