Class PagedLayer<T>

java.lang.Object
com.github.darksoulq.abyssallib.world.gui.layer.PagedLayer<T>
Type Parameters:
T - the type of data being paginated
All Implemented Interfaces:
GuiLayer

public class PagedLayer<T> extends Object implements GuiLayer
A GUI layer designed for paginating generic data objects into GUI elements.

This layer manages a source list of data, applies filtering logic, and maps a specific "window" of that data to inventory slots based on the current page.

  • Constructor Details

    • PagedLayer

      public PagedLayer(List<T> source, int[] slots, GuiView.Segment segment, BiFunction<T, Integer, GuiElement> mapper)
      Constructs a PagedLayer with a custom data-to-element mapper.
      Parameters:
      source - the master data list
      slots - the target slots for items
      segment - the target inventory segment
      mapper - the function creating elements from data
    • PagedLayer

      public PagedLayer(List<T> source, int[] slots, GuiView.Segment segment)
      Constructs a PagedLayer for direct GuiElement pagination.
      Parameters:
      source - the list of GUI elements
      slots - the target slots for items
      segment - the target inventory segment
  • Method Details

    • setFilter

      public void setFilter(Predicate<T> filter)
      Updates the data filter and resets the view to the first page.
      Parameters:
      filter - the data predicate
    • next

      public void next(GuiView view)
      Advances to the next page of content.
      Parameters:
      view - the active GUI view context
    • previous

      public void previous(GuiView view)
      Returns to the previous page of content.
      Parameters:
      view - the active GUI view context
    • renderTo

      public void renderTo(GuiView view)
      Renders the current page of data as GUI elements.

      Calculations are performed to slice the filtered data list and map results to the configured slot indices.

      Specified by:
      renderTo in interface GuiLayer
      Parameters:
      view - the view instance to render into
    • cleanup

      public void cleanup(GuiView view)
      Cleans up the rendered items and removed mapped elements.
      Specified by:
      cleanup in interface GuiLayer
      Parameters:
      view - the view instance being cleaned up
    • getPageCount

      public int getPageCount()
      Calculates the total number of pages based on filtered data size.
      Returns:
      the total page count
    • getPage

      public int getPage()
      Gets the current page index.
      Returns:
      current page
    • invalidate

      public void invalidate()
      Forces the layer to re-render.
    • of

      public static <T> PagedLayer<T> of(List<T> source, int[] slots, GuiView.Segment segment, BiFunction<T, Integer, GuiElement> mapper)
      Static helper for creating a generic PagedLayer.
      Type Parameters:
      T - data type
      Parameters:
      source - data source
      slots - target slots
      segment - target segment
      mapper - mapping function
      Returns:
      a new PagedLayer
    • of

      public static PagedLayer<GuiElement> of(List<GuiElement> elements, int[] slots, GuiView.Segment segment)
      Static helper for creating an element-specific PagedLayer.
      Parameters:
      elements - list of GUI elements
      slots - target slots
      segment - target segment
      Returns:
      a new PagedLayer for GUI elements