Class WBox
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.WBox
Similar to the BoxLayout in Swing, this widget represents a list of widgets along an axis.
- Since:
- 2.0.0
-
Field Summary
Modifier and TypeFieldDescriptionprotected Axis
The axis that the widgets are laid out on.protected HorizontalAlignment
The horizontal alignment for this box's children.protected int
The spacing between widgets.protected VerticalAlignment
The vertical alignment for this box's children.Fields inherited from class io.github.cottonmc.cotton.gui.widget.WPanelWithInsets
insets
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a widget to this box.void
Adds a widget to this box.getAxis()
Gets the axis of this box.Gets the horizontal alignment of this box.int
Gets the spacing between widgets.Gets the vertical alignment of this box.void
layout()
Uses this Panel's layout rules to reposition and resize components to fit nicely in the panel.Sets the axis of this box.setHorizontalAlignment
(HorizontalAlignment alignment) Sets the horizontal alignment of this box.Sets the layout insets of this panel.setSpacing
(int spacing) Sets the spacing between widgets in this box.setVerticalAlignment
(VerticalAlignment alignment) Sets the vertical alignment of this box.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, 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
-
spacing
protected int spacingThe spacing between widgets. -
axis
The axis that the widgets are laid out on. -
horizontalAlignment
The horizontal alignment for this box's children.- Since:
- 2.1.0
-
verticalAlignment
The vertical alignment for this box's children.- Since:
- 2.1.0
-
-
Constructor Details
-
WBox
Constructs a box.- Parameters:
axis
- the box axis- Throws:
NullPointerException
- if the axis is null
-
-
Method Details
-
add
Adds a widget to this box. If the widget is resizeable, resizes it to the provided dimensions.- Parameters:
widget
- the widgetwidth
- the new width of the widgetheight
- the new height of the widget
-
add
Adds a widget to this box. If the widget is resizeable, resizes it to 18x18.- Parameters:
widget
- the widget
-
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. -
getSpacing
public int getSpacing()Gets the spacing between widgets.- Returns:
- the spacing
-
setSpacing
Sets the spacing between widgets in this box.- Parameters:
spacing
- the new spacing- Returns:
- this box
-
getAxis
Gets the axis of this box.- Returns:
- the axis
-
setAxis
Sets the axis of this box.- Parameters:
axis
- the new axis- Returns:
- this box
- Throws:
NullPointerException
- if the axis is null
-
getHorizontalAlignment
Gets the horizontal alignment of this box.- Returns:
- the alignment
- Since:
- 2.1.0
-
setHorizontalAlignment
Sets the horizontal alignment of this box.- Parameters:
alignment
- the new alignment- Returns:
- this box
- Throws:
NullPointerException
- if the alignment is null- Since:
- 2.1.0
-
getVerticalAlignment
Gets the vertical alignment of this box.- Returns:
- the alignment
- Since:
- 2.1.0
-
setVerticalAlignment
Sets the vertical alignment of this box.- Parameters:
alignment
- the new alignment- Returns:
- this box
- Throws:
NullPointerException
- if the alignment is null- Since:
- 2.1.0
-
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
-