API VPanel - shmellyorc/Box GitHub Wiki

VPanel

Namespace: Box.Entities.Container

Description

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

Constructors

public VPanel(int spacing, params Entity[] children);
public VPanel(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 the entire column of children within the panel. Changes mark the panel dirty.
HAlign HAlign Horizontal alignment (Left, Center, Right) of each child within its allotted column width. 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 column: computes total height, aligns the start offset, and steps through each visible child setting Position. Resizes the panel if AutoSize is enabled. void

Examples

// Create a vertical menu of labels
var label1 = new Label("Option 1");
var label2 = new Label("Option 2");
var label3 = new Label("Option 3");

// Arrange them vertically with 10px spacing and center horizontally
var menu = new VPanel(10, label1, label2, label3)
{
    AutoSize = true,
    VAlign = VAlign.Top,
    HAlign = HAlign.Center
};

mainScreen.AddEntity(menu);