Table of Contents

Class HudCollection<TElementContainer, TElement>

Namespace
RichHudFramework.UI
Assembly
RichHudClient.dll

Generic collection of HUD elements, each wrapped in a decorator container. Elements inside containers are parented directly to this collection (not to their containers). Supports full IList-like manipulation while ensuring proper registration/unregistration with the HUD tree.

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

Type Parameters

TElementContainer

Type of the container/decorator wrapping each element. Must implement IHudNodeContainer<TElement>.

TElement

Actual HUD element type stored in each container.

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

Remarks

The HudCollection class serves as the fundamental storage mechanism for managing ordered lists of HUD elements. By pairing child elements with customizable wrapper objects (implementing IHudNodeContainer<TElement>), the collection allows developers to associate metadata or extend functionality without modifying the underlying element.

This infrastructure is the foundation for several key layout and control types:

  • HudChain<TElementContainer, TElement>: Uses the collection to implement linear layout logic, organizing elements into vertical or horizontal stacks. Unlike standard parenting, the chain order determines the visual sequence. Chain-specific wrappers (implementing IChainElementContainer<TElement>) introduce layout properties such as AlignAxisScale. These properties work in conjunction with the SizingMode to control the dynamic sizing and alignment of members within the stack.
  • ScrollBox<TElementContainer, TElement>: Builds upon the HudChain architecture to create scrollable regions. It utilizes a specialized container interface that adds an Enabled property. This allows specific entries to be dynamically hidden or shown within the scrolling list without creating layout gaps or removing them from the underlying collection.
  • SelectionBoxBase<TChain, TContainer, TElement>: Extends the collection functionality to support complex interaction patterns and data binding. By implementing interfaces such as IEntryBox<TContainer, TElement>, these types associate UI elements with data tuples (via IScrollBoxEntryTuple and ISelectionBoxEntryTuple) and often integrate object pooling. This flexibility supports the creation of mixed-type lists, where distinct entry types—such as simple labels and folder groups—can coexist within the same structure.

A key advantage of this modular design is the decoupling of storage and layout. Because the container logic is generic, a specific control can often be configured to use either a static HudChain or a scrolling ScrollBox by simply changing the generic type argument, while retaining the same entry management logic.

Constructors

HudCollection(HudParentBase)

public HudCollection(HudParentBase parent = null)

Parameters

parent HudParentBase

Properties

Collection

Read-only access to the list of element containers in this collection.

public IReadOnlyList<TElementContainer> Collection { get; }

Property Value

IReadOnlyList<TElementContainer>

CollectionContainer

Enables collection-initializer syntax (e.g., new HudCollection { element1, element2 }). Returns this instance so initializers can chain with container additions.

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

Property Value

HudCollection<TElementContainer, TElement>

Count

Number of containers currently in the collection.

public int Count { get; }

Property Value

int

IsReadOnly

Always false — this collection is mutable.

public bool IsReadOnly { get; }

Property Value

bool

this[int]

Indexer providing access to the container at the specified position.

public TElementContainer this[int index] { get; }

Parameters

index int

Property Value

TElementContainer

Methods

Add(TElementContainer)

Adds a pre-constructed container to the end of the collection. The container's element will be registered as a child of this collection.

public virtual void Add(TElementContainer container)

Parameters

container TElementContainer

Exceptions

Exception

Thrown if the element is already registered elsewhere or registration fails.

Add(TElement)

Adds a raw TElement by automatically wrapping it in a new TElementContainer.

public virtual void Add(TElement element)

Parameters

element TElement

AddRange(IReadOnlyList<TElementContainer>)

Adds multiple pre-constructed containers to the end of the collection in a single operation. All elements are registered as children of this collection.

public virtual void AddRange(IReadOnlyList<TElementContainer> newContainers)

Parameters

newContainers IReadOnlyList<TElementContainer>

Clear()

Removes all containers from the collection. Regular child elements (added directly via normal parenting) are not affected.

public virtual void Clear()

Contains(TElementContainer)

Determines whether the collection contains the specified container.

public virtual bool Contains(TElementContainer item)

Parameters

item TElementContainer

Returns

bool

CopyTo(TElementContainer[], int)

Copies the collection's containers to an array starting at the specified index.

public virtual void CopyTo(TElementContainer[] array, int arrayIndex)

Parameters

array TElementContainer[]
arrayIndex int

Find(Func<TElementContainer, bool>)

Returns the first container matching the predicate, or default(TElementContainer) if none found.

public virtual TElementContainer Find(Func<TElementContainer, bool> predicate)

Parameters

predicate Func<TElementContainer, bool>

Returns

TElementContainer

FindIndex(Func<TElementContainer, bool>)

Returns the index of the first container matching the predicate, or -1 if none found.

public virtual int FindIndex(Func<TElementContainer, bool> predicate)

Parameters

predicate Func<TElementContainer, bool>

Returns

int

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<TElementContainer> GetEnumerator()

Returns

IEnumerator<TElementContainer>

An enumerator that can be used to iterate through the collection.

Insert(int, TElementContainer)

Inserts a container at the specified index.

public virtual void Insert(int index, TElementContainer container)

Parameters

index int
container TElementContainer

InsertRange(int, IReadOnlyList<TElementContainer>)

Inserts a range of containers starting at the specified index.

public virtual void InsertRange(int index, IReadOnlyList<TElementContainer> newContainers)

Parameters

index int
newContainers IReadOnlyList<TElementContainer>

Remove(Func<TElementContainer, bool>)

Removes the first container that matches the given predicate.

public virtual bool Remove(Func<TElementContainer, bool> predicate)

Parameters

predicate Func<TElementContainer, bool>

Returns

bool

true if a matching container was found and removed.

Remove(TElementContainer)

Removes the specified container if it belongs to this collection.

public virtual bool Remove(TElementContainer entry)

Parameters

entry TElementContainer

Returns

bool

true if the container was removed and its element unregistered successfully.

RemoveAt(int)

Removes the container at the specified index.

public virtual bool RemoveAt(int index)

Parameters

index int

Returns

bool

true if removal and unregistration succeeded.

RemoveChild(HudNodeBase)

Overrides RemoveChild(HudNodeBase) to handle removal of elements that were added via the collection. Ensures both the container list and regular child tracking stay in sync.

public override bool RemoveChild(HudNodeBase child)

Parameters

child HudNodeBase

Returns

bool

RemoveRange(int, int)

Removes a contiguous range of containers starting at index. Only affects collection members — regular (non-collection) children are untouched.

public virtual void RemoveRange(int index, int count)

Parameters

index int
count int

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

IEnumerator IEnumerable.GetEnumerator()

Returns

IEnumerator

An IEnumerator object that can be used to iterate through the collection.