Class DropdownListField

java.lang.Object
de.gurkenlabs.litiengine.gui.GuiComponent
de.gurkenlabs.litiengine.gui.DropdownListField
All Implemented Interfaces:
IRenderable, Tweenable, MouseListener, MouseMotionListener, MouseWheelListener, EventListener

public class DropdownListField extends GuiComponent
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 Details

    • ARROW_DOWN

      public static final FontIcon 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 new DropdownListField.
      Parameters:
      x - the x coordinate of the component
      y - the y coordinate of the component
      width - the width of the component
      height - the total height of the component including the drop-down list
      content - the selectable values
      elementsShown - the number of list entries that are simultaneously shown when the drop-down is open
  • Method Details

    • getButtonSprite

      public Spritesheet getButtonSprite()
      Gets the spritesheet used to render the drop-down button.
      Returns:
      the button spritesheet
    • getChangeConsumer

      public List<IntConsumer> getChangeConsumer()
      Gets the list of registered change listeners.
      Returns:
      the change listener list
    • getChosenElementComponent

      public ImageComponent getChosenElementComponent()
      Gets the component that displays the currently selected element when the drop-down is collapsed.
      Returns:
      the chosen element component
    • getContentArray

      public Object[] getContentArray()
      Gets the array of selectable values.
      Returns:
      the content array
    • getContentList

      public ListField getContentList()
      Gets the internal list field used to render the drop-down entries.
      Returns:
      the content list
    • getDropDownButton

      public ImageComponent getDropDownButton()
      Gets the toggle button used to open and close the drop-down.
      Returns:
      the drop-down toggle button
    • getEntrySprite

      public Spritesheet getEntrySprite()
      Gets the spritesheet used to render the drop-down entries.
      Returns:
      the entry spritesheet
    • getListEntries

      public List<ImageComponent> 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

      public Object getSelectedObject()
      Gets the currently selected value.
      Returns:
      the selected value, or null if the content array is empty
    • isArrowKeyNavigation

      public boolean isArrowKeyNavigation()
      Returns whether arrow-key navigation is enabled.
      Returns:
      true if the selection can be changed using arrow keys / mouse wheel while the component is hovered
    • isDroppedDown

      public boolean isDroppedDown()
      Returns whether the drop-down is currently expanded.
      Returns:
      true if the drop-down list is shown
    • onChange

      public void onChange(IntConsumer c)
      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: GuiComponent
      Prepare 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:
      prepare in class GuiComponent
    • setArrowKeyNavigation

      public void setArrowKeyNavigation(boolean arrowKeyNavigation)
      Sets whether arrow-key (and mouse-wheel) navigation should be used to change the selection while the component is hovered.
      Parameters:
      arrowKeyNavigation - true to enable arrow-key navigation
    • setButtonSprite

      public void setButtonSprite(Spritesheet buttonSprite)
      Sets the spritesheet used to render the drop-down toggle button.
      Parameters:
      buttonSprite - the spritesheet
    • setEntrySprite

      public void setEntrySprite(Spritesheet entrySprite)
      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

      public void setSelection(Object selectedObject)
      Sets the selection by value. The first entry that equals the given object is selected.
      Parameters:
      selectedObject - the value to select; ignored if null
    • toggleDropDown

      public void toggleDropDown()
      Toggle drop down.