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
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The scroll pane shown when a select box is open. -
Constructor Summary
ConstructorDescriptionTextraSelectBox
(com.badlogic.gdx.scenes.scene2d.ui.Skin skin) TextraSelectBox
(com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName) -
Method Summary
Modifier and TypeMethodDescriptionvoid
act
(float delta) void
void
draw
(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) protected void
drawItem
(com.badlogic.gdx.graphics.g2d.Batch batch, TextraLabel item, float x, float y, float width) protected com.badlogic.gdx.scenes.scene2d.utils.Drawable
Returns appropriate background drawable from the style based on the current select box state.com.badlogic.gdx.scenes.scene2d.utils.ClickListener
protected com.badlogic.gdx.graphics.Color
Returns 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.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
com.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.void
hideList()
Deprecated.void
boolean
boolean
isOver()
void
layout()
protected TextraLabel
protected TextraSelectBox.SelectBoxScrollPane
Allows a subclass to customize the scroll pane shown when the select box is open.protected void
onHide
(com.badlogic.gdx.scenes.scene2d.Actor scrollPane) protected void
onShow
(com.badlogic.gdx.scenes.scene2d.Actor scrollPane, boolean below) void
setAlignment
(int alignment) Sets the alignment of the selected item in the select box.void
setDisabled
(boolean disabled) void
setItems
(com.badlogic.gdx.utils.Array<? extends TextraLabel> newItems) Sets the items visible in the select box.void
setItems
(TextraLabel... newItems) Set the backing Array that makes up the choices available in the SelectBox.void
setItemTexts
(String... newMarkupTexts) Sets the choices available in the SelectBox using an array or varargs of markup Strings.void
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
(TextraLabel 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.protected void
setStage
(com.badlogic.gdx.scenes.scene2d.Stage stage) void
setStyle
(Styles.SelectBoxStyle style) void
showList()
Deprecated.UseshowScrollPane()
.void
protected String
toString
(TextraLabel item) Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
Methods 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:
setStage
in 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 innewMarkupTexts
as 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:
layout
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout
- Overrides:
layout
in 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:
draw
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
act
public void act(float delta) - Overrides:
act
in 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:
setDisabled
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Disableable
-
isDisabled
public boolean isDisabled()- Specified by:
isDisabled
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Disableable
-
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidth
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout
- Overrides:
getPrefWidth
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeight
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout
- Overrides:
getPrefHeight
in 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()
.