Table of Contents

Class HudChain<TElementContainer, TElement>

Namespace
RichHudFramework.UI
Assembly
RichHudClient.dll

Organizes child elements into a linear stack, either horizontally or vertically. Conceptually similar to a CSS Flexbox or a UI StackPanel.

public class HudChain<TElementContainer, TElement> : HudCollection<TElementContainer, TElement>, IReadOnlyHudElement, IReadOnlyHudNode, IReadOnlyHudParent, IHudCollection<TElementContainer, TElement>, IReadOnlyHudCollection<TElementContainer, TElement>, IReadOnlyList<TElementContainer>, IReadOnlyCollection<TElementContainer>, IEnumerable<TElementContainer>, IEnumerable where TElementContainer : IChainElementContainer<TElement>, new() where TElement : HudElementBase

Type Parameters

TElementContainer
TElement
Inheritance
HudCollection<TElementContainer, TElement>
HudChain<TElementContainer, TElement>
Implements
IHudCollection<TElementContainer, TElement>
IReadOnlyHudCollection<TElementContainer, TElement>
IReadOnlyList<TElementContainer>
IReadOnlyCollection<TElementContainer>
IEnumerable<TElementContainer>
Derived
Inherited Members

Examples

The following example demonstrates how to create a horizontal row (chain) containing a label, a button, and a dropdown. The label retains its natural size, while the button and dropdown are configured to split the remaining horizontal width equally.

var row = new HudChain(parent)
{
    // Make chain horizontal
    AlignVertical = false,
    // Define the external bounds and spacing
    UnpaddedSize = new Vector2(300f, 40f),
    Padding = new Vector2(10f),
    Spacing = 8f,
    // Force members to match the chain's height (Off Axis) 
    // and allow the chain to calculate width distribution (Align Axis).
    SizingMode = HudChainSizingModes.FitMembersOffAxis,
    CollectionContainer = 
    {
        // Element 1: Label
        // AlignAxisScale is 0f: It keeps its calculated width.
        { new Label { Text = "Row Label" }, 0f }, 
        // Element 2: Button
        // AlignAxisScale is 0.5f: It takes 50% of the *remaining* space.
        { new BorderedButton { Text = "Action" }, 0.5f }, 
        // Element 3: Dropdown
        // AlignAxisScale is 0.5f: It takes the other 50% of remaining space.
        { new Dropdown<int>
        {
            ListContainer =
            {
                { "Mode 1", 1 },
                { "Mode 2", 2 },
                { "Mode 3", 3 }
            }
        }, 0.5f }
    }
};

Remarks

This class extends HudCollection and serves as a fundamental layout tool that organizes child HudElementBase elements into a linear stack, either vertically or horizontally. Conceptually similar to a CSS Flexbox or a XAML StackPanel, it provides the underlying logic for automatically arranging UI elements without manual pixel positioning.

Layout and Sizing

The orientation of the stack is controlled by the AlignVertical property. In the framework's terminology, the direction of the stack is the Align Axis (Y for vertical, X for horizontal), while the perpendicular direction is the Off Axis. Layout behavior is further defined by HudChainSizingModes, which determines whether the chain expands to fit its members or clamps them to its own fixed size. Individual elements can be set to fixed sizes or configured to scale proportionally to fill remaining space using the AlignAxisScale property on their containers.

Usage and Derivatives

While this generic class allows for full customization of container types, the framework includes convenience aliases—HudChain<TElementContainer> and HudChain—which utilize default container and element types for standard use cases. This infrastructure also forms the foundation for scrollable lists, such as ScrollBox<TElementContainer, TElement>, and complex controls like SelectionBoxBase<TChain, TContainer, TElement>.

Tip

Although the framework does not include a native grid container, complex 2D layouts can be achieved by nesting vertical and horizontal chains.

Constructors

HudChain()

public HudChain()

HudChain(HudParentBase)

public HudChain(HudParentBase parent)

Parameters

parent HudParentBase

HudChain(bool, HudParentBase)

public HudChain(bool alignVertical = false, HudParentBase parent = null)

Parameters

alignVertical bool
parent HudParentBase

Properties

AlignVertical

If true, elements are stacked vertically (Top to Bottom). If false, elements are stacked horizontally (Left to Right).

public virtual bool AlignVertical { get; set; }

Property Value

bool

CollectionContainer

Enables nested collection-initializer syntax.

public HudChain<TElementContainer, TElement> CollectionContainer { get; }

Property Value

HudChain<TElementContainer, TElement>

MemberMaxSize

The maximum size allowed for a chain member.

Note: Requires a Fit/Clamp member sizing mode to be effective on a specific axis.

public Vector2 MemberMaxSize { get; set; }

Property Value

Vector2

MemberMinSize

The minimum size allowed for a chain member.

Note: Requires a Clamp member sizing mode. Has no effect if FitMembers is set.

public Vector2 MemberMinSize { get; set; }

Property Value

Vector2

SizingMode

Defines how the chain resizes itself and how it resizes its children. Default is FitChainBoth.

public HudChainSizingModes SizingMode { get; set; }

Property Value

HudChainSizingModes

Spacing

The gap between chain elements along the alignment axis.

public float Spacing { get; set; }

Property Value

float

Methods

Add(TElement, float)

Adds a UI element to the end of the chain.

public virtual void Add(TElement element, float alignAxisScale)

Parameters

element TElement

The element to add.

alignAxisScale float

Determines how excess space is distributed on the alignment axis.

0f = Element keeps its fixed size (default behavior).

> 0f = Element scales proportionally relative to other weighted elements to fill remaining space.

Note: Overridden if Fit/ClampMemberAlignAxis sizing flags are set.

GetRangeSize(int, int)

Calculates the combined size of the chain elements within the given index range.

public virtual Vector2 GetRangeSize(int start = 0, int end = -1)

Parameters

start int

Start index.

end int

End index (-1 for last element).

Returns

Vector2

Total size vector (Width, Height) required to fit the range.

SetRangeSize(Vector2, int, int)

Forces the size of members within the specified index range.

Axes set to 0 in newSize retain their original size.

public virtual Vector2 SetRangeSize(Vector2 newSize, int start = 0, int end = -1)

Parameters

newSize Vector2
start int
end int

Returns

Vector2

The calculated total size of the affected members.