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.WBox
Similar to the BoxLayout in Swing, this widget represents a list of widgets along an axis.
- Since:
- 2.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AxisThe axis that the widgets are laid out on.protected HorizontalAlignmentThe horizontal alignment for this box's children.protected intThe spacing between widgets.protected VerticalAlignmentThe vertical alignment for this box's children. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a widget to this box.voidAdds a widget to this box.getAxis()Gets the axis of this box.Gets the horizontal alignment of this box.Gets the layout insets of this box.intGets the spacing between widgets.Gets the vertical alignment of this box.voidlayout()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 box.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.WPanel
addPainters, canResize, createPeers, cycleFocus, cycleFocus, expandToFit, expandToFit, getBackgroundPainter, hit, onHidden, onShown, paint, remove, setBackgroundPainter, tick, toString, validateMethods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addTooltip, canFocus, getAbsoluteX, getAbsoluteY, getHeight, getHost, getParent, getWidth, getX, getY, isActivationKey, isFocused, isWithinBounds, onCharTyped, onClick, onFocusGained, onFocusLost, onKeyPressed, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, releaseFocus, renderTooltip, requestFocus, setHost, setLocation, setParent, setSize
-
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:WPanelUses 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
-
getInsets
Gets the layout insets of this box.- Returns:
- the insets
- Since:
- 4.0.0
-
setInsets
Sets the layout insets of this box.The insets should be set before adding any widgets to this box.
- Parameters:
insets- the insets, should not be null- Returns:
- this box
- Since:
- 4.0.0
-