API HPanel - shmellyorc/Box GitHub Wiki

HPanel

Namespace: Box.Entities.Container

Description

A horizontal layout panel that arranges its child entities in a row, with configurable spacing, alignment, and optional auto-sizing. When marked dirty, it recalculates each child’s position based on the panel’s width, chosen horizontal and vertical alignments, and spacing between items.

Constructors

public HPanel(int spacing, params Entity[] children);
public HPanel(params Entity[] children);

Creates the panel, stores spacing, adds any initial children, and performs an initial resize if auto-size is enabled.

Properties

Property Description
bool AutoSize When true, the panel automatically adjusts its size to fit its visible children. Changing this marks the panel dirty.
VAlign VAlign Vertical alignment (Top, Middle, Bottom) of each child within its allotted row height. Changes mark the panel dirty.
HAlign HAlign Horizontal alignment (Left, Center, Right) of the entire row of children within the panel. Changes mark the panel dirty.
int Spacing Spacing in pixels between adjacent child entities. Changes mark the panel dirty.

Methods

Method Signature Description Returns
protected override void UpdateDirtyState() Recalculates child positions in a single row: computes total width, aligns the start offset, and steps through each visible child setting Position. Resizes the panel if AutoSize is enabled. void

Examples

// Create buttons for a toolbar
var playBtn = new Button("Play");
var pauseBtn = new Button("Pause");
var stopBtn = new Button("Stop");

// Arrange them horizontally with 10px spacing and center alignment
var toolbar = new HPanel(10, playBtn, pauseBtn, stopBtn)
{
    AutoSize = true,
    HAlign = HAlign.Center,
    VAlign = VAlign.Middle
};

mainScreen.AddEntity(toolbar);