Class WListPanel<D,W extends WWidget>


public class WListPanel<D,W extends WWidget> extends WClippedPanel
Similar to the RecyclerView in Android, this widget represents a scrollable list of items.

D is the type of data represented. The data must reside in some ordered backing List<D>. D's *must* have working equals and hashCode methods to distinguish them from each other!

W is the WWidget class that will represent a single D of data.

  • Field Details

    • data

      protected List<D> data
      The list of data that this list represents.
    • supplier

      protected Supplier<W extends WWidget> supplier
      The supplier of new empty widgets.
    • configurator

      protected BiConsumer<D,W extends WWidget> configurator
      The widget configurator that configures the passed widget to display the passed data.
    • configured

      protected HashMap<D,W extends WWidget> configured
    • unconfigured

      protected List<W extends WWidget> unconfigured
    • cellHeight

      protected int cellHeight
      The height of each child cell.
    • fixedHeight

      protected boolean fixedHeight
      Whether this list has a fixed height for items.
    • scrollBar

      protected WScrollBar scrollBar
      The scroll bar of this list.
  • Constructor Details

    • WListPanel

      public WListPanel(List<D> data, Supplier<W> supplier, BiConsumer<D,W> configurator)
      Constructs a list panel.
      Parameters:
      data - the list data
      supplier - the widget supplier that creates unconfigured widgets
      configurator - the widget configurator that configures widgets to display the passed data
  • Method Details

    • paint

      @Environment(CLIENT) public void paint(DrawContext context, int x, int y, int mouseX, int mouseY)
      Description copied from class: WWidget
      Paints this widget.
      Overrides:
      paint in class WClippedPanel
      Parameters:
      context - the draw context
      x - this widget's X coordinate on the screen
      y - this widget's Y coordinate on the screen
      mouseX - the X coordinate of the cursor
      mouseY - the X coordinate of the cursor
    • validate

      public void validate(GuiDescription c)
      Description copied from class: WPanel
      Creates component peers and initializes animation data for this Widget and all its children. The host screen handler must clear any heavyweight peers from its records before this method is called.

      This method must be called on the root panel of any screen once the widgets have been initialized.

      Subclasses should call super.validate(c) to ensure that children are validated.

      Overrides:
      validate in class WPanel
      Parameters:
      c - the host GUI description
    • setHost

      public void setHost(GuiDescription host)
      Description copied from class: WWidget
      Sets the host of this widget and all its children without creating peers.
      Overrides:
      setHost in class WPanel
      Parameters:
      host - the new host
      See Also:
    • addPainters

      public void addPainters()
      Description copied from class: WPanel
      Adds the default background painters to this widget and all children.

      Always called before GuiDescription.addPainters() to allow users to modify painters.

      Subclasses should call super.addPainters() to ensure that children have proper default painters.

      Overrides:
      addPainters in class WPanel
    • layout

      public void layout()
      Description copied from class: WPanel
      Uses this Panel's layout rules to reposition and resize components to fit nicely in the panel.
      Overrides:
      layout in class WPanel
    • setListItemHeight

      public WListPanel<D,W> setListItemHeight(int height)
      Sets the height of this list's items to a constant value.
      Parameters:
      height - the item height
      Returns:
      this list
    • onMouseScroll

      public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount)
      Description copied from class: WWidget
      Notifies this widget that the mouse has been scrolled inside its bounds.
      Overrides:
      onMouseScroll in class WWidget
      Parameters:
      x - The X coordinate of the event, in widget-space (0 is the left edge of this widget)
      y - The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
      horizontalAmount - The scrolled horizontal amount. Positive values are right and negative values are left.
      verticalAmount - The scrolled vertical amount. Positive values are up and negative values are down.
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • getScrollBar

      public WScrollBar getScrollBar()
      Gets the WScrollBar attached to this panel.
      Returns:
      the scroll bar bundled
      Since:
      5.3.0
    • getInsets

      public Insets getInsets()
      Returns the layout insets used for the contents of this list.
      Returns:
      the layout insets used for the contents of this list
      Since:
      9.1.0
    • setInsets

      public WListPanel<D,W> setInsets(Insets insets)
      Sets the layout insets used for the contents of this list.
      Parameters:
      insets - the layout insets
      Returns:
      this list
      Since:
      9.1.0
    • getGap

      public int getGap()
      Returns the gap between list items.
      Returns:
      the gap between list items
      Since:
      9.1.0
    • setGap

      public WListPanel<D,W> setGap(int gap)
      Sets the gap between list items.
      Parameters:
      gap - the gap, must be non-negative
      Returns:
      this list
      Since:
      9.1.0