libgdx API

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

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

public class SelectBox
extends Widget

A select box (aka a drop-down list) allows a user to choose one of a number of values from a list. When inactive, the selected value is displayed. When activated, it shows the list of values that may be selected.

The preferred size of the select box is determined by the maximum text bounds of the items and the size of the SelectBox.SelectBoxStyle.background.

Author:
mzechner

Nested Class Summary
static class SelectBox.SelectBoxStyle
          The style for a select box, see SelectBox.
 
Field Summary
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, stage, touchable, visible, width, x, y
 
Constructor Summary
SelectBox(java.lang.Object[] items, SelectBox.SelectBoxStyle style)
           
SelectBox(java.lang.Object[] items, SelectBox.SelectBoxStyle style, java.lang.String name)
           
SelectBox(java.lang.Object[] items, Skin skin)
           
SelectBox(Skin skin)
           
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.
 float getPrefHeight()
           
 float getPrefWidth()
           
 java.lang.String getSelection()
           
 int getSelectionIndex()
           
 SelectBox.SelectBoxStyle getStyle()
          Returns the select box's style.
 void layout()
          Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child and calls Layout.invalidate() and then Layout.validate() on each one.
 void markToRemove(boolean remove)
          Marks the Actor to be removed by its parent.
 void setItems(java.lang.Object[] objects)
           
 void setSelection(int selection)
          Sets the selected item via it's index
 void setSelection(java.lang.String item)
           
 void setSelectionListener(SelectionListener listener)
          Sets the SelectionListener.
 void setStyle(SelectBox.SelectBoxStyle style)
           
 boolean touchDown(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, needsLayout, pack, setFillParent, toScreenCoordinates, touchDragged, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, getStage, isMarkedToRemove, keyDown, keyTyped, keyUp, remove, scrolled, toLocalCoordinates, toString, touchMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SelectBox

public SelectBox(Skin skin)

SelectBox

public SelectBox(java.lang.Object[] items,
                 Skin skin)

SelectBox

public SelectBox(java.lang.Object[] items,
                 SelectBox.SelectBoxStyle style)

SelectBox

public SelectBox(java.lang.Object[] items,
                 SelectBox.SelectBoxStyle style,
                 java.lang.String name)
Method Detail

setStyle

public void setStyle(SelectBox.SelectBoxStyle style)

getStyle

public SelectBox.SelectBoxStyle getStyle()
Returns the select box's style. Modifying the returned style may not have an effect until setStyle(SelectBoxStyle) is called.


setItems

public void setItems(java.lang.Object[] objects)

layout

public void layout()
Description copied from interface: Layout
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child and calls Layout.invalidate() and then Layout.validate() on each one. Usually this should not be called directly, instead Layout.validate() should be used.

Specified by:
layout in interface Layout
Overrides:
layout in class Widget

draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
Description copied from class: Widget
If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.

Overrides:
draw in class Widget
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

touchDown

public boolean touchDown(float x,
                         float y,
                         int pointer)
Overrides:
touchDown in class Widget

touchUp

public void touchUp(float x,
                    float y,
                    int pointer)
Overrides:
touchUp in class Widget

setSelectionListener

public void setSelectionListener(SelectionListener listener)
Sets the SelectionListener.

Parameters:
listener - the listener or null

setSelection

public void setSelection(int selection)
Sets the selected item via it's index

Parameters:
selection - the selection index

setSelection

public void setSelection(java.lang.String item)

getSelectionIndex

public int getSelectionIndex()
Returns:
the index of the current selection. The top item has an index of 0

getSelection

public java.lang.String getSelection()
Returns:
the string of the currently selected item

getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout
Overrides:
getPrefWidth in class Widget

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout
Overrides:
getPrefHeight in class Widget

markToRemove

public void markToRemove(boolean remove)
Description copied from class: Actor
Marks the Actor to be removed by its parent.

The actual removal happens in the Group.act(float) method of the parent and after the parent has called Actor.act(float) on this Actor.

Overrides:
markToRemove in class Actor
Parameters:
remove - whether the parent is supposed to remove this Actor

libgdx API

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