Package com.github.tommyettinger.textra
Class TextraSelectBox
java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.github.tommyettinger.textra.TextraSelectBox
- All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Disableable,com.badlogic.gdx.scenes.scene2d.utils.Layout
- Direct Known Subclasses:
TypingSelectBox
public class TextraSelectBox
extends com.badlogic.gdx.scenes.scene2d.ui.Widget
implements com.badlogic.gdx.scenes.scene2d.utils.Disableable
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 select box selection changes.
The preferred size of the select box is determined by the maximum text bounds of the items and the size of the
Styles.SelectBoxStyle.background. You cannot currently rely on setting a containing Cell's
Cell.maxSize(float, float) (or minSize).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe scroll pane shown when a select box is open. -
Field Summary
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
POOLS -
Constructor Summary
ConstructorsConstructorDescriptionTextraSelectBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin) TextraSelectBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName) -
Method Summary
Modifier and TypeMethodDescriptionvoidact(float delta) voidvoiddraw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) protected voiddrawItem(com.badlogic.gdx.graphics.g2d.Batch batch, TextraLabel item, float x, float y, float width) protected com.badlogic.gdx.scenes.scene2d.utils.DrawableReturns appropriate background drawable from the style based on the current select box state.com.badlogic.gdx.scenes.scene2d.utils.ClickListenerprotected com.badlogic.gdx.graphics.ColorReturns the appropriate label font color from the style based on the current button state.com.badlogic.gdx.utils.Array<TextraLabel>getItems()Returns the internal items array.getList()Returns the list shown when the select box is open.intfloatReturns the pref width of the select box if the widest item was selected, for use whensetSelectedPrefWidth(boolean)is true.floatfloatReturns the scroll pane containing the list that is shown when the select box is open.Returns the first selected item, or null.intbooleancom.badlogic.gdx.scenes.scene2d.utils.ArraySelection<TextraLabel>Get the set of selected items, useful when multiple items are selectedgetStyle()Returns the select box's style.voidhideList()Deprecated.voidbooleanbooleanisOver()voidlayout()protected TextraLabelprotected TextraSelectBox.SelectBoxScrollPaneAllows a subclass to customize the scroll pane shown when the select box is open.protected voidonHide(com.badlogic.gdx.scenes.scene2d.Actor scrollPane) protected voidonShow(com.badlogic.gdx.scenes.scene2d.Actor scrollPane, boolean below) voidsetAlignment(int alignment) Sets the alignment of the selected item in the select box.voidsetDisabled(boolean disabled) voidsetItems(com.badlogic.gdx.utils.Array<? extends TextraLabel> newItems) Sets the items visible in the select box.voidsetItems(TextraLabel... newItems) Set the backing Array that makes up the choices available in the SelectBox.voidsetItemTexts(String... newMarkupTexts) Sets the choices available in the SelectBox using an array or varargs of markup Strings.voidsetMaxListCount(int maxListCount) Set the max number of items to display when the select box is opened.voidsetScrollingDisabled(boolean y) Disables scrolling of the list shown when the select box is open.voidsetSelected(TextraLabel item) Sets the selection to only the passed item, if it is a possible choice, else selects the first item.voidsetSelectedIndex(int index) Sets the selection to only the selected index.voidsetSelectedPrefWidth(boolean selectedPrefWidth) When true the pref width is based on the selected item.protected voidsetStage(com.badlogic.gdx.scenes.scene2d.Stage stage) voidsetStyle(Styles.SelectBoxStyle style) voidshowList()Deprecated.UseshowScrollPane().voidprotected StringtoString(TextraLabel item) Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validateMethods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, drawDebugBounds, 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, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, 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
-
TextraSelectBox
public TextraSelectBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin) -
TextraSelectBox
-
TextraSelectBox
-
-
Method Details
-
newScrollPane
Allows a subclass to customize the scroll pane shown when the select box is open. -
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.
-
setStage
protected void setStage(com.badlogic.gdx.scenes.scene2d.Stage stage) - Overrides:
setStagein classcom.badlogic.gdx.scenes.scene2d.Actor
-
setStyle
-
getStyle
Returns the select box's style. Modifying the returned style may not have an effect untilsetStyle(Styles.SelectBoxStyle)is called. -
setItemTexts
Sets the choices available in the SelectBox using an array or varargs of markup Strings. Marks up each String innewMarkupTextsas a TextraLabel and adds that label to the choices.- Parameters:
newMarkupTexts- an array or varargs of individual markup Strings, one per choice
-
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()- Specified by:
layoutin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
layoutin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getBackgroundDrawable
@Null protected com.badlogic.gdx.scenes.scene2d.utils.Drawable getBackgroundDrawable()Returns appropriate background drawable from the style based on the current select box state. -
getFontColor
protected com.badlogic.gdx.graphics.Color getFontColor()Returns the appropriate label font color from the style based on the current button state. -
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) - Overrides:
drawin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
act
public void act(float delta) - Overrides:
actin classcom.badlogic.gdx.scenes.scene2d.Actor
-
drawItem
protected void drawItem(com.badlogic.gdx.graphics.g2d.Batch batch, TextraLabel item, float x, float y, float width) -
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 useSelectBox.getSelection(). -
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() -
getMaxPrefWidth
public float getMaxPrefWidth()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:
setDisabledin interfacecom.badlogic.gdx.scenes.scene2d.utils.Disableable
-
isDisabled
public boolean isDisabled()- Specified by:
isDisabledin interfacecom.badlogic.gdx.scenes.scene2d.utils.Disableable
-
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidthin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefWidthin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeightin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefHeightin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
toString
-
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
public com.badlogic.gdx.scenes.scene2d.utils.ClickListener getClickListener() -
onShow
protected void onShow(com.badlogic.gdx.scenes.scene2d.Actor scrollPane, boolean below) -
onHide
protected void onHide(com.badlogic.gdx.scenes.scene2d.Actor scrollPane) -
newLabel
-
hideScrollPane().