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
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 Summary
ConstructorsConstructorDescriptionScrollLayer(List<T> source, int[] slots, GuiView.Segment segment, int scrollStep, BiFunction<T, Integer, GuiElement> mapper) Constructs a new ScrollLayer. -
Method Summary
Modifier and TypeMethodDescriptionvoidCleans up the current scroll slots by removing element mappings and clearing the item stacks from the actual inventory.intCalculates the maximum valid scroll offset.intGets the current scroll offset.voidInvalidates the render cache, forcing the layer to re-render on the next tick.voidRenders the current "window" of the data list to the inventory view.voidscrollDown(GuiView view) Shifts the view window downward by the defined scroll step.voidShifts the view window upward by the defined scroll step.voidSets the scroll offset to a specific index.
-
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
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
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
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
Renders the current "window" of the data list to the inventory view.It maps data from
source[scrollOffset]tosource[scrollOffset + slots.length]and places the resulting elements into the defined slots. -
cleanup
-
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.
-