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
Modifier and TypeFieldDescriptionprotected int
The 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 boolean
Whether this list has a fixed height for items.protected WScrollBar
The scroll bar of this list.The supplier of new empty widgets. -
Constructor Summary
ConstructorDescriptionWListPanel
(List<D> data, Supplier<W> supplier, BiConsumer<D, W> configurator) Constructs a list panel. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the default background painters to this widget and all children.int
getGap()
Returns the gap between list items.Returns the layout insets used for the contents of this list.Gets theWScrollBar
attached to this panel.void
layout()
Uses this Panel's layout rules to reposition and resize components to fit nicely in the panel.onMouseScroll
(int x, int y, double horizontalAmount, double verticalAmount) Notifies this widget that the mouse has been scrolled inside its bounds.void
paint
(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.WListPanel
<D, W> setGap
(int gap) Sets the gap between list items.void
setHost
(GuiDescription host) Sets the host of this widget and all its children without creating peers.WListPanel
<D, W> Sets the layout insets used for the contents of this list.WListPanel
<D, W> setListItemHeight
(int height) Sets the height of this list's items to a constant value.void
Creates component peers and initializes animation data for this Widget and all its children.Methods inherited from class io.github.cottonmc.cotton.gui.widget.WPanel
canResize, expandToFit, expandToFit, getBackgroundPainter, hit, onHidden, onShown, remove, setBackgroundPainter, streamChildren, tick, toString
Methods 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. -
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:WWidget
Paints this widget.- Overrides:
paint
in 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: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. -
setHost
Description copied from class:WWidget
Sets the host of this widget and all its children without creating peers. -
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 classWPanel
-
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. -
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:WWidget
Notifies this widget that the mouse has been scrolled inside its bounds.- Overrides:
onMouseScroll
in 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)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
Gets theWScrollBar
attached to this panel.- Returns:
- the scroll bar bundled
- Since:
- 5.3.0
-
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
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
Sets the gap between list items.- Parameters:
gap
- the gap, must be non-negative- Returns:
- this list
- Since:
- 9.1.0
-