Class GridLayout

java.lang.Object
xyz.gmitch215.socketmc.screen.layout.AbstractLayout
xyz.gmitch215.socketmc.screen.layout.GridLayout
All Implemented Interfaces:
Serializable, Layout, LayoutElement

public final class GridLayout extends AbstractLayout
Represents a layout with elements in a grid format. The Grid Layout starts with a size of 0, and is expanded as elements are added.
See Also:
  • Constructor Details

    • GridLayout

      public GridLayout()
      Creates a new GridLayout at the origin.
    • GridLayout

      public GridLayout(int x, int y)
      Creates a new GridLayout with the specified position.
      Parameters:
      x - The X position
      y - The Y position
  • Method Details

    • getChildren

      @NotNull public @NotNull List<LayoutElement> getChildren()
      Gets an immutable copy of the children in the GridLayout.
      Returns:
      GridLayout Children
    • getCells

      @NotNull public @NotNull List<GridLayout.Cell> getCells()
      Gets an immutable copy of the cells in the GridLayout.
      Returns:
      GridLayout Cells
    • getRowSpacing

      public int getRowSpacing()
      Gets the row spacing between cells.
      Returns:
      Row Spacing
    • setRowSpacing

      @NotNull public @NotNull GridLayout setRowSpacing(int rowSpacing)
      Sets the row spacing between cells.
      Parameters:
      rowSpacing - Row Spacing
      Returns:
      this class, for chaining
    • getColumnSpacing

      public int getColumnSpacing()
      Gets the column spacing between cells.
      Returns:
      Column Spacing
    • setColumnSpacing

      @NotNull public @NotNull GridLayout setColumnSpacing(int columnSpacing)
      Sets the column spacing between cells.
      Parameters:
      columnSpacing - Column Spacing
      Returns:
      this class, for chaining
    • setSpacing

      @NotNull public @NotNull GridLayout setSpacing(int spacing)
      Sets the row and column spacing between cells.
      Parameters:
      spacing - The spacing
      Returns:
      this class, for chaining
    • setSpacing

      @NotNull public @NotNull GridLayout setSpacing(int row, int column)
      Sets the row and column spacing between cells.
      Parameters:
      row - The row spacing
      column - The column spacing
      Returns:
      this class, for chaining
    • addCell

      @NotNull public <T extends LayoutElement> T addCell(@NotNull T element, int row, int column) throws IllegalArgumentException
      Adds a cell to the GridLayout using the default layout settings.
      Type Parameters:
      T - The type of the element
      Parameters:
      element - The element to add
      row - The row of the cell
      column - The column of the cell
      Returns:
      The element that was added
      Throws:
      IllegalArgumentException - if the element or size is null or the row/column coordinates are negative
    • addCell

      @NotNull public <T extends LayoutElement> T addCell(@NotNull T element, int row, int column, int occupiedRows, int occupiedColumns) throws IllegalArgumentException
      Adds a cell to the GridLayout using the default layout settings.
      Type Parameters:
      T - The type of the element
      Parameters:
      element - The element to add
      row - The row of the cell
      column - The column of the cell
      occupiedRows - The number of rows the cell occupies
      occupiedColumns - The number of columns the cell occupies
      Returns:
      The element that was added
      Throws:
      IllegalArgumentException - if the element or size is null, the row/column coordinates are negative, or the occupied size is less than 1
    • addCell

      @NotNull public <T extends LayoutElement> T addCell(@NotNull T element, int row, int column, @NotNull @NotNull LayoutSettings settings) throws IllegalArgumentException
      Adds a cell to the GridLayout.
      Type Parameters:
      T - The type of the element
      Parameters:
      element - The element to add
      row - The row of the cell
      column - The column of the cell
      settings - The layout settings for the cell
      Returns:
      The element that was added
      Throws:
      IllegalArgumentException - if the element or size is null or the row/column coordinates are negative
    • addCell

      @NotNull public <T extends LayoutElement> T addCell(@NotNull T element, int row, int column, int occupiedRows, int occupiedColumns, @NotNull @NotNull LayoutSettings settings) throws IllegalArgumentException
      Adds a cell to the GridLayout.
      Type Parameters:
      T - The type of the element
      Parameters:
      element - The element to add
      row - The row of the cell
      column - The column of the cell
      occupiedRows - The number of rows the cell occupies
      occupiedColumns - The number of columns the cell occupies
      settings - The layout settings for the cell
      Returns:
      The element that was added
      Throws:
      IllegalArgumentException - if the element or size is null, the row/column coordinates are negative, or the occupied size is less than 1
    • addCell

      @NotNull public <T extends LayoutElement> T addCell(@NotNull T element, int row, int column, @NotNull @NotNull Supplier<LayoutSettings> settings) throws IllegalArgumentException
      Adds a cell to the GridLayout.
      Type Parameters:
      T - The type of the element
      Parameters:
      element - The element to add
      row - The row of the cell
      column - The column of the cell
      settings - The generator for the cell settings
      Returns:
      The element that was added
      Throws:
      IllegalArgumentException - if the element or size is null or the row/column coordinates are negative
    • addCell

      @NotNull public <T extends LayoutElement> T addCell(@NotNull T element, int row, int column, int occupiedRows, int occupiedColumns, @NotNull @NotNull Supplier<LayoutSettings> settings) throws IllegalArgumentException
      Adds a cell to the GridLayout.
      Type Parameters:
      T - The type of the element
      Parameters:
      element - The element to add
      row - The row of the cell
      column - The column of the cell
      occupiedRows - The number of rows the cell occupies
      occupiedColumns - The number of columns the cell occupies
      settings - The generator for the cell settings
      Returns:
      The element that was added
      Throws:
      IllegalArgumentException - if the element or size is null, the row/column coordinates are negative, or the occupied size is less than 1
    • addCell

      @NotNull public <T extends LayoutElement> T addCell(@NotNull T element, int row, int column, @NotNull @NotNull Consumer<LayoutSettings> settings) throws IllegalArgumentException
      Adds a cell to the GridLayout.
      Type Parameters:
      T - The type of the element
      Parameters:
      element - The element to add
      row - The row of the cell
      column - The column of the cell
      settings - The function to apply to createDefaultSettings()
      Returns:
      The element that was added
      Throws:
      IllegalArgumentException - if the element or size is null or the row/column coordinates are negative
    • addCell

      @NotNull public <T extends LayoutElement> T addCell(@NotNull T element, int row, int column, int occupiedRows, int occupiedColumns, @NotNull @NotNull Consumer<LayoutSettings> settings) throws IllegalArgumentException
      Adds a cell to the GridLayout.
      Type Parameters:
      T - The type of the element
      Parameters:
      element - The element to add
      row - The row of the cell
      column - The column of the cell
      occupiedRows - The number of rows the cell occupies
      occupiedColumns - The number of columns the cell occupies
      settings - The function to apply to createDefaultSettings()
      Returns:
      The element that was added
      Throws:
      IllegalArgumentException - if the element or size is null, the row/column coordinates are negative, or the occupied size is less than 1
    • createDefaultSettings

      @NotNull public @NotNull LayoutSettings createDefaultSettings()
      Description copied from interface: Layout
      Generates the default layout settings for this layout.
      Returns:
      Default Layout Settings
    • visitChildren

      public void visitChildren(@NotNull @NotNull Consumer<LayoutElement> visitor)
      Description copied from interface: Layout
      Visits this layout and all of its children.
      Parameters:
      visitor - Element Visitor
    • arrangeElements

      public void arrangeElements()
      Description copied from interface: Layout
      Arranges the elements inside this Layout.
    • addElement

      @Deprecated public <T extends LayoutElement> T addElement(@NotNull T element, @NotNull @NotNull LayoutSettings settings) throws IllegalArgumentException
      Description copied from interface: Layout
      Adds an element to this layout.
      Type Parameters:
      T - the type of the element
      Parameters:
      element - the element to add
      settings - the settings for the element
      Returns:
      the added element
      Throws:
      IllegalArgumentException - if the element or settings are null
    • newRow

      Creates a new RowHelper with one column.
      Returns:
      RowHelper
    • newRow

      @NotNull public @NotNull GridLayout.RowHelper newRow(int columns)
      Creates a new RowHelper with the specified number of columns.
      Parameters:
      columns - The number of columns
      Returns:
      RowHelper