API GridPanel - shmellyorc/Box GitHub Wiki

GridPanel

Namespace: Box.Entities.Container

Description

Represents a grid panel that arranges child entities by column count instead of by width. Child entities are laid out in rows of a fixed number of columns, with configurable horizontal and vertical spacing. The panel can automatically resize to fit its visible children and supports per-cell alignment.

Constructor

public GridPanel(int columns, params Entity[] children)

Sets the column count (minimum of 1), adds any initial children, and performs an initial resize to accommodate content.

Properties

Property Description
int Columns Number of columns in the grid layout; determines how many items appear per row before wrapping.
int HorizontalSpacing Spacing in pixels between entities along the horizontal axis.
int VerticalSpacing Spacing in pixels between entities along the vertical axis.
bool AutoSize When enabled, the panel automatically adjusts its size based on its visible children.
HAlign HAlign Horizontal alignment of each entity within its cell (Left, Center, Right).
VAlign VAlign Vertical alignment of each entity within its cell (Top, Middle, Bottom).

Methods

Method Signature Description Returns
protected override void UpdateDirtyState() Recalculates positions for visible children in a grid (using column and row indices, spacing, and alignment), resizes the panel if AutoSize is true, then calls base.UpdateDirtyState(). void

Examples

// Create a grid of inventory slots (4 columns)
var slot1 = new InventorySlot();
var slot2 = new InventorySlot();
// ... more slots
var grid = new GridPanel(4, slot1, slot2, slot3, slot4)
{
    HorizontalSpacing = 8,
    VerticalSpacing = 8,
    AutoSize = true,
    HAlign = HAlign.Center,
    VAlign = VAlign.Middle
};

mainScreen.AddEntity(grid);