Class WListPanel<D,W extends WWidget>
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WPanel
io.github.cottonmc.cotton.gui.widget.WClippedPanel
io.github.cottonmc.cotton.gui.widget.WListPanel<D,W>
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 Summary
FieldsModifier and TypeFieldDescriptionprotected intThe height of each child cell.protected BiConsumer<D,W> The widget configurator that configures the passed widget to display the passed data.The list of data that this list represents.protected booleanWhether this list has a fixed height for items.protected intprotected WScrollBarThe scroll bar of this list.The supplier of new empty widgets. -
Constructor Summary
ConstructorsConstructorDescriptionWListPanel(List<D> data, Supplier<W> supplier, BiConsumer<D, W> configurator) Constructs a list panel. -
Method Summary
Modifier and TypeMethodDescriptionGets theWScrollBarattached to this panel.voidlayout()Uses this Panel's layout rules to reposition and resize components to fit nicely in the panel.onMouseScroll(int x, int y, double amount) Notifies this widget that the mouse has been scrolled inside its bounds.voidpaint(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.voidsetHost(GuiDescription host) Sets the host of this widget and all its children without creating peers.WListPanel<D,W> setListItemHeight(int height) Sets the height of this list's items to a constant value.voidCreates component peers and initializes animation data for this Widget and all its children.Methods inherited from class io.github.cottonmc.cotton.gui.widget.WPanel
addPainters, canResize, expandToFit, expandToFit, getBackgroundPainter, hit, onHidden, onShown, remove, setBackgroundPainter, streamChildren, tick, toStringMethods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addNarrations, addTooltip, canFocus, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onCharTyped, onClick, onFocusGained, onFocusLost, onKeyPressed, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseUp, releaseFocus, renderTooltip, requestFocus, setHovered, setLocation, setParent, setSize, shouldRenderInDarkMode
-
Field Details
-
data
The list of data that this list represents. -
supplier
The supplier of new empty widgets. -
configurator
The widget configurator that configures the passed widget to display the passed data. -
configured
-
unconfigured
-
cellHeight
protected int cellHeightThe height of each child cell. -
fixedHeight
protected boolean fixedHeightWhether this list has a fixed height for items. -
margin
protected int margin -
scrollBar
The scroll bar of this list.
-
-
Constructor Details
-
WListPanel
Constructs a list panel.- Parameters:
data- the list datasupplier- the widget supplier that creates unconfigured widgetsconfigurator- the widget configurator that configures widgets to display the passed data
-
-
Method Details
-
paint
Description copied from class:WWidgetPaints this widget.- Overrides:
paintin classWClippedPanel- Parameters:
context- the draw contextx- this widget's X coordinate on the screeny- this widget's Y coordinate on the screenmouseX- the X coordinate of the cursormouseY- the X coordinate of the cursor
-
validate
Description copied from class:WPanelCreates 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. -
setHost
Description copied from class:WWidgetSets the host of this widget and all its children without creating peers. -
layout
public void layout()Description copied from class:WPanelUses this Panel's layout rules to reposition and resize components to fit nicely in the panel. -
setListItemHeight
Sets the height of this list's items to a constant value.- Parameters:
height- the item height- Returns:
- this list
-
onMouseScroll
Description copied from class:WWidgetNotifies this widget that the mouse has been scrolled inside its bounds.- Overrides:
onMouseScrollin classWWidget- 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)amount- The scrolled amount. Positive values are up and negative values are down.- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
getScrollBar
Gets theWScrollBarattached to this panel.- Returns:
- the scroll bar bundled
- Since:
- 5.3.0
-