Class WGridPanel
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WPanel
io.github.cottonmc.cotton.gui.widget.WPanelWithInsets
io.github.cottonmc.cotton.gui.widget.WGridPanel
A panel that positions children in a grid.
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
The grid size in pixels.protected int
The horizontal gap between two grid cells.protected int
The vertical gap between two grid cells.Fields inherited from class io.github.cottonmc.cotton.gui.widget.WPanelWithInsets
insets
-
Constructor Summary
ConstructorDescriptionConstructs a grid panel with the default grid size.WGridPanel
(int gridSize) Constructs a grid panel with a custom grid size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a widget to this panel.void
Adds a widget to this panel and resizes it to a custom size.setGaps
(int horizontalGap, int verticalGap) Set the gaps between grid cells.Sets the layout insets of this panel.Methods inherited from class io.github.cottonmc.cotton.gui.widget.WPanelWithInsets
expandToFit, getInsets
Methods inherited from class io.github.cottonmc.cotton.gui.widget.WPanel
addPainters, canResize, expandToFit, getBackgroundPainter, hit, layout, onHidden, onShown, paint, remove, setBackgroundPainter, setHost, streamChildren, tick, toString, validate
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, onMouseScroll, onMouseUp, releaseFocus, renderTooltip, requestFocus, setHovered, setLocation, setParent, setSize, shouldRenderInDarkMode
-
Field Details
-
grid
protected int gridThe grid size in pixels. Defaults to 18, which is the size of one item slot. -
horizontalGap
protected int horizontalGapThe horizontal gap between two grid cells.- Since:
- 6.4.0
-
verticalGap
protected int verticalGapThe vertical gap between two grid cells.- Since:
- 6.4.0
-
-
Constructor Details
-
WGridPanel
public WGridPanel()Constructs a grid panel with the default grid size. -
WGridPanel
public WGridPanel(int gridSize) Constructs a grid panel with a custom grid size.- Parameters:
gridSize
- the grid size in pixels
-
-
Method Details
-
setGaps
Set the gaps between grid cells.This method can only be called before any elements get added to this layout.
- Parameters:
horizontalGap
- the horizontal gap between grid cellsverticalGap
- the vertical gap between grid cells- Since:
- 6.4.0
-
add
Adds a widget to this panel.If the widget can be resized, it will be resized to (
grid
,grid
).- Parameters:
w
- the widgetx
- the X position in grid cellsy
- the Y position in grid cells
-
add
Adds a widget to this panel and resizes it to a custom size.- Parameters:
w
- the widgetx
- the X position in grid cellsy
- the Y position in grid cellswidth
- the new width in grid cellsheight
- the new height in grid cells
-
setInsets
Description copied from class:WPanelWithInsets
Sets the layout insets of this panel. Subclasses are encouraged to override this method to return their more specific type (such asWGridPanel
).If there are already widgets in this panel when the insets are modified, the panel is resized and the widgets are moved according to the insets.
- Overrides:
setInsets
in classWPanelWithInsets
- Parameters:
insets
- the insets, should not be null- Returns:
- this panel
-