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
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.Fields inherited from class io.github.cottonmc.cotton.gui.widget.WPanelWithInsets
insets -
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.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 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, getInsetsMethods inherited from class io.github.cottonmc.cotton.gui.widget.WPanel
addPainters, canResize, expandToFit, getBackgroundPainter, hit, onHidden, onShown, paint, remove, setBackgroundPainter, setHost, streamChildren, tick, toString, validateMethods 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: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
-
setInsets
Description copied from class:WPanelWithInsetsSets 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:
setInsetsin classWPanelWithInsets- Parameters:
insets- the insets, should not be null- Returns:
- this panel
-