API CenterPanel - shmellyorc/Box GitHub Wiki

CenterPanel

Namespace: Box.Entities.Container

Description

Represents a panel that centers its child entities within its own dimensions, optionally snapping their positions to the nearest pixel and applying an additional offset. Whenever its layout changes (due to offset or rounding), it marks itself dirty and recalculates child positions.

Constructors

public CenterPanel(params Entity[] children)

Constructors pass provided entities to the base Panel and set default behavior (RoundedToPixel = true, Offset = Vect2.Zero).

Properties

Property Description
bool RoundedToPixel Whether child positions are snapped to the nearest pixel. Changing this repositions children on next update.
Vect2 Offset Additional translation applied after centering each child. Changing this repositions children on next update.

Methods

Method Signature Description Returns
protected override void Update() If debug drawing is enabled, renders a green outline of the panel bounds, then invokes base.Update() to handle layout and child updates. void
protected override void UpdateDirtyState() Recalculates each child’s position to center it within the panel (Vect2.Center(Size, child.Size, RoundedToPixel) + Offset), then clears the dirty flag. void

Examples

// Center a UI widget at screen center with a slight upward offset.
var widget = new ScoreDisplay();
var centerPanel = new CenterPanel(widget)
{
    RoundedToPixel = false,
    Offset = new Vect2(0, -20)
};

mainScreen.AddEntity(centerPanel);