Package com.prineside.tdi2.scene2d.ui
Class SelectBox<T>
java.lang.Object
com.prineside.tdi2.scene2d.Actor
com.prineside.tdi2.scene2d.ui.Widget
com.prineside.tdi2.scene2d.ui.SelectBox<T>
- All Implemented Interfaces:
Disableable
,Layout
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.
ChangeListener.ChangeEvent
is fired when the selectbox selection changes.
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, Nathan Sweet
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The scroll pane shown when a select box is open.static class
The style for a select box, seeSelectBox
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
If this method is overridden, the super method orWidget.validate()
should be called to ensure the widget is laid out.getItems()
Returns the internal items array.getList()
Returns the list shown when the select box is open.int
float
Returns the pref width of the select box if the widest item was selected, for use whensetSelectedPrefWidth(boolean)
is true.float
float
Returns the scroll pane containing the list that is shown when the select box is open.Returns the first selected item, or null.int
boolean
Get the set of selected items, useful when multiple items are selectedgetStyle()
Returns the select box's style.void
hideList()
Deprecated.void
boolean
boolean
isOver()
void
layout()
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsLayout.invalidate()
on any each child whose width or height has changed, and callsLayout.validate()
on each child.void
setAlignment
(int alignment) Sets the alignment of the selected item in the select box.void
setDisabled
(boolean disabled) void
Sets the items visible in the select box.void
Set the backing Array that makes up the choices available in the SelectBoxvoid
setMaxListCount
(int maxListCount) Set the max number of items to display when the select box is opened.void
setScrollingDisabled
(boolean y) Disables scrolling of the list shown when the select box is open.void
setSelected
(T item) Sets the selection to only the passed item, if it is a possible choice, else selects the first item.void
setSelectedIndex
(int index) Sets the selection to only the selected index.void
setSelectedPrefWidth
(boolean selectedPrefWidth) When true the pref width is based on the selected item.void
setStyle
(SelectBox.SelectBoxStyle style) void
showList()
Deprecated.UseshowScrollPane()
.void
Methods inherited from class com.prineside.tdi2.scene2d.ui.Widget
getMaxHeight, getMaxHeightValue, getMaxWidth, getMaxWidthValue, getMinHeight, getMinHeightValue, getMinWidth, getMinWidthValue, getPrefHeightValue, getPrefWidthValue, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setPrefHeight, setPrefHeight, setPrefWidth, setPrefWidth, validate
Methods inherited from class com.prineside.tdi2.scene2d.Actor
act, addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, hit, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
-
Constructor Details
-
SelectBox
-
-
Method Details
-
setMaxListCount
public void setMaxListCount(int maxListCount) Set the max number of items to display when the select box is opened. Set to 0 (the default) to display as many as fit in the stage height. -
getMaxListCount
public int getMaxListCount()- Returns:
- Max number of items to display when the box is opened, or <= 0 to display them all.
-
setStyle
-
getStyle
Returns the select box's style. Modifying the returned style may not have an effect untilsetStyle(SelectBoxStyle)
is called. -
setItems
Set the backing Array that makes up the choices available in the SelectBox -
setItems
Sets the items visible in the select box. -
clearItems
public void clearItems() -
getItems
Returns the internal items array. If modified,setItems(Array)
must be called to reflect the changes. -
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, callsLayout.invalidate()
on any each child whose width or height has changed, and callsLayout.validate()
on each child. This method should almost never be called directly, insteadLayout.validate()
should be used. -
draw
Description copied from class:Widget
If this method is overridden, the super method orWidget.validate()
should be called to ensure the widget is laid out. -
setAlignment
public void setAlignment(int alignment) Sets the alignment of the selected item in the select box. SeegetList()
andList.setAlignment(int)
to set the alignment in the list shown when the select box is open.- Parameters:
alignment
- SeeAlign
.
-
getSelection
Get the set of selected items, useful when multiple items are selected- Returns:
- a Selection object containing the selected elements
-
getSelected
Returns the first selected item, or null. For multiple selections usegetSelection()
. -
setSelected
Sets the selection to only the passed item, if it is a possible choice, else selects the first item. -
getSelectedIndex
public int getSelectedIndex()- Returns:
- The index of the first selected item. The top item has an index of 0. Nothing selected has an index of -1.
-
setSelectedIndex
public void setSelectedIndex(int index) Sets the selection to only the selected index. -
setSelectedPrefWidth
public void setSelectedPrefWidth(boolean selectedPrefWidth) When true the pref width is based on the selected item. -
getSelectedPrefWidth
public boolean getSelectedPrefWidth() -
getMaxSelectedPrefWidth
public float getMaxSelectedPrefWidth()Returns the pref width of the select box if the widest item was selected, for use whensetSelectedPrefWidth(boolean)
is true. -
setDisabled
public void setDisabled(boolean disabled) - Specified by:
setDisabled
in interfaceDisableable
-
isDisabled
public boolean isDisabled()- Specified by:
isDisabled
in interfaceDisableable
-
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidth
in interfaceLayout
- Overrides:
getPrefWidth
in classWidget
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeight
in interfaceLayout
- Overrides:
getPrefHeight
in classWidget
-
showList
Deprecated.UseshowScrollPane()
. -
showScrollPane
public void showScrollPane() -
hideList
Deprecated.UsehideScrollPane()
. -
hideScrollPane
public void hideScrollPane() -
getList
Returns the list shown when the select box is open. -
setScrollingDisabled
public void setScrollingDisabled(boolean y) Disables scrolling of the list shown when the select box is open. -
getScrollPane
Returns the scroll pane containing the list that is shown when the select box is open. -
isOver
public boolean isOver() -
getClickListener
-
hideScrollPane()
.