Class DropdownListField
java.lang.Object
de.gurkenlabs.litiengine.gui.GuiComponent
de.gurkenlabs.litiengine.gui.DropdownListField
- All Implemented Interfaces:
IRenderable, Tweenable, MouseListener, MouseMotionListener, MouseWheelListener, EventListener
A GUI component that displays a single selected entry from a list of choices and reveals the full list as a drop-down when the user clicks the
accompanying arrow button. The selection can also be navigated with arrow keys or the mouse wheel when
arrow key navigation is enabled.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FontIconDown-pointing arrow icon shown on the drop-down toggle button.Fields inherited from class GuiComponent
ICON_FONT -
Constructor Summary
ConstructorsConstructorDescriptionDropdownListField(double x, double y, double width, double height, Object[] content, int elementsShown) Constructs a newDropdownListField. -
Method Summary
Modifier and TypeMethodDescriptionGets the spritesheet used to render the drop-down button.Gets the list of registered change listeners.Gets the component that displays the currently selected element when the drop-down is collapsed.Object[]Gets the array of selectable values.Gets the internal list field used to render the drop-down entries.Gets the toggle button used to open and close the drop-down.Gets the spritesheet used to render the drop-down entries.Gets the list of rendered drop-down entry components.intGets the maximum number of list entries that are shown simultaneously.intGets the index of the currently selected entry.Gets the currently selected value.booleanReturns whether arrow-key navigation is enabled.booleanReturns whether the drop-down is currently expanded.voidRegisters a callback that is invoked with the new selected index whenever the selection changes.voidprepare()Prepare the GuiComponent and all its child Components (Makes the GuiComponent visible and adds mouse listeners.).voidsetArrowKeyNavigation(boolean arrowKeyNavigation) Sets whether arrow-key (and mouse-wheel) navigation should be used to change the selection while the component is hovered.voidsetButtonSprite(Spritesheet buttonSprite) Sets the spritesheet used to render the drop-down toggle button.voidsetEntrySprite(Spritesheet entrySprite) Sets the spritesheet used to render the drop-down entries.voidsetSelection(int selectionIndex) Sets the selection by index.voidsetSelection(Object selectedObject) Sets the selection by value.voidToggle drop down.Methods inherited from class GuiComponent
addRenderedListener, addRenderListener, getAppearance, getAppearanceDisabled, getAppearanceHovered, getBoundingBox, getCenterX, getCenterY, getClickConsumer, getComponentId, getComponents, getCurrentAppearance, getFocusedComponent, getFont, getHeight, getHoverConsumer, getHoverSound, getLocation, getMouseDraggedConsumer, getMouseEnterConsumer, getMouseLeaveConsumer, getMouseMovedConsumer, getMousePressedConsumer, getMouseReleasedConsumer, getMouseWheelConsumer, getName, getShape, getTag, getText, getTextAlign, getTextAngle, getTextShadowColor, getTextShadowRadius, getTextToRender, getTextValign, getTextX, getTextY, getTweenValues, getWidth, getX, getY, hasAutomaticLineBreaks, hasInputFocus, hasTextAntialiasing, hasTextShadow, initializeComponents, isAutoScaling, isEnabled, isFocusable, isForwardMouseEvents, isHovered, isPressed, isSelected, isSuspended, isVisible, mouseClicked, mouseDragged, mouseEntered, mouseEventShouldBeForwarded, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, onClicked, onHovered, onMouseDragged, onMouseEnter, onMouseLeave, onMouseMoved, onMousePressed, onMouseReleased, onMouseWheelScrolled, onResolutionChanged, onTextChanged, removeListener, removeListener, render, setAutomaticLineBreaks, setAutoScaling, setDimension, setEnabled, setFocusable, setFont, setFontSize, setForwardMouseEvents, setHeight, setHovered, setHoverSound, setLocation, setLocation, setName, setSelected, setTag, setText, setTextAlign, setTextAngle, setTextAntialiasing, setTextShadow, setTextShadowColor, setTextShadowRadius, setTextValign, setTextX, setTextY, setTweenValues, setVisible, setWidth, setX, setY, suspend, toggleSelection, toggleSuspension
-
Field Details
-
ARROW_DOWN
Down-pointing arrow icon shown on the drop-down toggle button.
-
-
Constructor Details
-
DropdownListField
public DropdownListField(double x, double y, double width, double height, Object[] content, int elementsShown) Constructs a newDropdownListField.- Parameters:
x- the x coordinate of the componenty- the y coordinate of the componentwidth- the width of the componentheight- the total height of the component including the drop-down listcontent- the selectable valueselementsShown- the number of list entries that are simultaneously shown when the drop-down is open
-
-
Method Details
-
getButtonSprite
Gets the spritesheet used to render the drop-down button.- Returns:
- the button spritesheet
-
getChangeConsumer
Gets the list of registered change listeners.- Returns:
- the change listener list
-
getChosenElementComponent
Gets the component that displays the currently selected element when the drop-down is collapsed.- Returns:
- the chosen element component
-
getContentArray
-
getContentList
Gets the internal list field used to render the drop-down entries.- Returns:
- the content list
-
getDropDownButton
Gets the toggle button used to open and close the drop-down.- Returns:
- the drop-down toggle button
-
getEntrySprite
Gets the spritesheet used to render the drop-down entries.- Returns:
- the entry spritesheet
-
getListEntries
Gets the list of rendered drop-down entry components.- Returns:
- the list entries
-
getNumberOfShownElements
public int getNumberOfShownElements()Gets the maximum number of list entries that are shown simultaneously.- Returns:
- the number of shown elements
-
getSelectedIndex
public int getSelectedIndex()Gets the index of the currently selected entry.- Returns:
- the selected index
-
getSelectedObject
Gets the currently selected value.- Returns:
- the selected value, or
nullif the content array is empty
-
isDroppedDown
public boolean isDroppedDown()Returns whether the drop-down is currently expanded.- Returns:
trueif the drop-down list is shown
-
onChange
Registers a callback that is invoked with the new selected index whenever the selection changes.- Parameters:
c- the change consumer
-
prepare
public void prepare()Description copied from class:GuiComponentPrepare the GuiComponent and all its child Components (Makes the GuiComponent visible and adds mouse listeners.). This is, for example, done right before switching to a new screen.- Overrides:
preparein classGuiComponent
-
setButtonSprite
Sets the spritesheet used to render the drop-down toggle button.- Parameters:
buttonSprite- the spritesheet
-
setEntrySprite
Sets the spritesheet used to render the drop-down entries.- Parameters:
entrySprite- the spritesheet
-
setSelection
public void setSelection(int selectionIndex) Sets the selection by index.- Parameters:
selectionIndex- the index of the entry to select
-
setSelection
-
toggleDropDown
public void toggleDropDown()Toggle drop down.
-