Class ScrollLayer<T>

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

public class ScrollLayer<T> extends Object implements GuiLayer
A GUI layer that facilitates a scrollable view of generic data objects.

Unlike pagination, which jumps between fixed groups of elements, the ScrollLayer allows for a dynamic offset within the source list. This creates a "window" that can slide through the data one step at a time.

  • Constructor Details

    • ScrollLayer

      public ScrollLayer(List<T> source, int[] slots, GuiView.Segment segment, int scrollStep, BiFunction<T, Integer, GuiElement> mapper)
      Constructs a new ScrollLayer.
      Parameters:
      source - The full list of data to display.
      slots - The array of slot indices used for rendering the window.
      segment - The inventory segment where slots are located.
      scrollStep - The number of indices to shift during scrollUp/scrollDown.
      mapper - The function to transform data into GUI elements.
  • Method Details

    • scrollDown

      public void scrollDown(GuiView view)
      Shifts the view window downward by the defined scroll step.

      The offset is clamped to the maximum possible scrollable index based on the source list size and the available slot count.

      Parameters:
      view - The active GUI view context.
    • scrollUp

      public void scrollUp(GuiView view)
      Shifts the view window upward by the defined scroll step.

      The offset is clamped to a minimum of 0.

      Parameters:
      view - The active GUI view context.
    • setScroll

      public void setScroll(GuiView view, int offset)
      Sets the scroll offset to a specific index.

      The provided offset is validated to ensure it falls within the range of 0 to the maximum possible scroll index.

      Parameters:
      view - The active GUI view context.
      offset - The new target scroll index.
    • renderTo

      public void renderTo(GuiView view)
      Renders the current "window" of the data list to the inventory view.

      It maps data from source[scrollOffset] to source[scrollOffset + slots.length] and places the resulting elements into the defined slots.

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

      public void cleanup(GuiView view)
      Cleans up the current scroll slots by removing element mappings and clearing the item stacks from the actual inventory.
      Specified by:
      cleanup in interface GuiLayer
      Parameters:
      view - The view instance being cleaned up.
    • getScrollOffset

      public int getScrollOffset()
      Gets the current scroll offset.
      Returns:
      The current starting index of the rendered window.
    • getMaxScroll

      public int getMaxScroll()
      Calculates the maximum valid scroll offset.
      Returns:
      The highest index that can be at the start of the window.
    • invalidate

      public void invalidate()
      Invalidates the render cache, forcing the layer to re-render on the next tick.