API AlignmentHelpers - shmellyorc/Box GitHub Wiki

Alignment Helpers

Namespace: Box.Helpers

Description: A static utility class providing methods to align sizes and positions of elements—such as UI controls, sprites, or game entities—relative to parent dimensions or the rendering viewport. It supports horizontal and vertical alignment modes (e.g., left, center, right; top, middle, bottom) with optional offset adjustments, streamlining common layout tasks in the game engine.


Constructors

This is a static class; there are no public constructors.


Properties

No public properties.


Methods

Method Signature Returns Description
AlignWidth static float AlignWidth(float parent, float child, HAlign hAlign, float offset) float Calculates horizontal position within parent for child using hAlign and applies offset.
AlignWidth static float AlignWidth(float parent, float child, HAlign hAlign) float Same as above with zero offset.
AlignHeight static float AlignHeight(float parent, float child, VAlign vAlign, float offset) float Calculates vertical position within parent for child using vAlign and applies offset.
AlignHeight static float AlignHeight(float parent, float child, VAlign vAlign) float Same as above with zero offset.
AlignToRenderer static Vect2 AlignToRenderer(Entity entity, HAlign hAlign, VAlign vAlign, Vect2 offset) Vect2 Computes position for entity relative to the rendering viewport using specified alignments and offset.
AlignToRenderer static Vect2 AlignToRenderer(Entity entity, HAlign hAlign, VAlign vAlign) Vect2 Same as above with zero offset.
AlignToEntity static Vect2 AlignToEntity(Entity parent, Entity child, HAlign hAlign, VAlign vAlign, Vect2 offset) Vect2 Calculates position for child within parent using alignments and offset.
AlignToEntity static Vect2 AlignToEntity(Entity parent, Entity child, HAlign hAlign, VAlign vAlign) Vect2 Same as above with zero offset.

Examples

// Center a UI panel of width 200 within a window of width 800 with no offset
float x = AlignmentHelpers.AlignWidth(800f, 200f, HAlign.Center);

// Align a sprite to the bottom-right of the screen with a 10px margin
Vect2 position = AlignmentHelpers.AlignToRenderer(mySprite, HAlign.Right, VAlign.Bottom, new Vect2(-10f, -10f));

// Place a child entity at the top-center of its parent
Vect2 childPos = AlignmentHelpers.AlignToEntity(parentEntity, childEntity, HAlign.Center, VAlign.Top);