|
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 item in the list of strings. Use
ComboBox#setPrefSize(int, int)
to change this size programmatically. In case the set size is to small to contain the
widest item, artifacts may appear.
The additional popup list will be positioned at the bottom edge of the ComboBox, displaying all items. The width and size is
governed by the background NinePatch
of the popup list as well as the bounding box around the list items.
Widget
displaying a background NinePatch
as well as the selected list item 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 item 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 itemsfontColor
attribute references a Color
by name, to be used to render the list items
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 |
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[] items,
Stage stage,
ComboBox.ComboBoxStyle style)
|
|
ComboBox(java.lang.String[] items,
Stage stage,
ComboBox.ComboBoxStyle style,
java.lang.String name)
Creates a new combo box. |
|
ComboBox(java.lang.String[] items,
Stage stage,
Skin skin)
|
Method Summary | |
---|---|
void |
draw(SpriteBatch batch,
float parentAlpha)
Draws the Actor. |
float |
getPrefHeight()
|
float |
getPrefWidth()
|
java.lang.String |
getSelection()
|
int |
getSelectionIndex()
|
void |
layout()
Positions and sizes each child of this actor. |
void |
setItems(java.lang.String[] items)
|
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 |
---|
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, hit, 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 ComboBox(java.lang.String[] items, Stage stage, Skin skin)
public ComboBox(java.lang.String[] items, Stage stage, ComboBox.ComboBoxStyle style)
public ComboBox(java.lang.String[] items, Stage stage, ComboBox.ComboBoxStyle style, java.lang.String name)
name
- the nameitems
- the single-line itemsstage
- the stage, used for the popupstyle
- the ComboBox.ComboBoxStyle
Method Detail |
---|
public void setStyle(ComboBox.ComboBoxStyle style)
style
- public void setItems(java.lang.String[] items)
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 float getPrefWidth()
public float getPrefHeight()
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |