Table of Contents

Class TreeBox<TContainer, TElement>

Namespace
RichHudFramework.UI
Assembly
RichHudClient.dll

Generic tree box supporting custom entry types of arbitrary height, provided they have a label.

public class TreeBox<TContainer, TElement> : TreeBoxBase<TContainer, TElement>, IReadOnlyHudElement, IReadOnlyHudNode, IReadOnlyHudParent, IMinLabelElement, IEntryBox<TContainer, TElement>, IEnumerable<TContainer>, IEnumerable, IValueControl<TContainer>, IValueControl, IClickableElement, IFocusableElement where TContainer : class, ISelectionBoxEntry<TElement>, new() where TElement : HudElementBase, IMinLabelElement

Type Parameters

TContainer

Container type that wraps each entry's UI element and provides selection/association data.

TElement

The actual UI element displayed for each entry (must support minimal labeling).

Inheritance
TreeBoxBase<TreeBoxBase<TContainer, TElement>.TreeChainSelectionBox, HudChain<TContainer, TElement>, TContainer, TElement>
TreeBoxBase<TContainer, TElement>
TreeBox<TContainer, TElement>
Implements
IEntryBox<TContainer, TElement>
IEnumerable<TContainer>
IValueControl<TContainer>
Derived
Inherited Members

Examples

TreeBox is a more generalized version of TreeList<TElement, TValue>. It trades uniform, pooled entries for entries of any type that extend LabelElementBase.

As seen below, this means additional setup is required for normal entries, but it also allows for heterogeneous entries. Labels, dropdowns, other TreeBoxes or custom elements can all be added to the same list.

private static Label GetCustomLabel(string name)
{
    return new Label
    {
        Format = GlyphFormat.Blueish,
        Text = name,
        AutoResize = false,
        Height = 28f,
        Padding = new Vector2(20f, 0f)
    };
}

new TreeBox<string>(parent)
{
    Name = "Custom TreeBox Label",
    ParentAlignment = ParentAlignments.InnerTop,
    UpdateValueCallback = (obj, args) =>
    {
        var treeList = (TreeBox<string>)obj;
        MyAPIGateway.Utilities.ShowMessage(
            $"[{treeList.GetType().Name}]",
            $"Selected: {treeList.Value.AssocMember}");
    },
    ListContainer =
    {
        { GetCustomLabel("Label 1"), "Key 1" },
        { GetCustomLabel("Label 2"), "Key 2" },
        { GetCustomLabel("Label 3"), "Key 3" },
        { GetCustomLabel("Label 4"), "Key 4" },
        {
            new TreeList<string>
            {
                Name = "Nested TreeList (5)",
                ParentAlignment = ParentAlignments.InnerTop,
                UpdateValueCallback = (obj, args) =>
                {
                    var treeList = (TreeList<string>)obj;
                    MyAPIGateway.Utilities.ShowMessage(
                        $"Nested [{treeList.GetType().Name}]",
                        $"Selected: {treeList.Value.AssocMember}");
                },
                ListContainer =
                {
                    { "Label 6", "Key 6" },
                    { "Label 7", "Key 7" },
                    { "Label 8", "Key 8" },
                    { "Label 9", "Key 9" },
                }
            },
            "Key 5", // Key for the nested tree
            false // Disable highlighting for the inner tree. It does its own highlighting.
        }
    }
};

Remarks

TreeBox<TValue> is used as an alias to simplify usage by defaulting TContainer and TElement to SelectionBoxEntryTuple<TElement, TValue> and LabelElementBase, respectively.

Constructors

TreeBox()

public TreeBox()

TreeBox(HudParentBase)

public TreeBox(HudParentBase parent)

Parameters

parent HudParentBase

Properties

this[int]

Returns the entry at the given index

public TContainer this[int index] { get; }

Parameters

index int

Property Value

TContainer

ListContainer

Enables collection-initializer syntax (e.g., new MyTreeBox { ListContainer = { entry1, entry2 } })

public TreeBox<TContainer, TElement> ListContainer { get; }

Property Value

TreeBox<TContainer, TElement>

Methods

Add(TContainer)

Adds an element of type TContainer to the collection.

public void Add(TContainer element)

Parameters

element TContainer

Add(TElement)

Adds an element of type TElement to the collection.

public void Add(TElement element)

Parameters

element TElement

AddRange(IReadOnlyList<TContainer>)

Add the given range to the end of the collection.

public void AddRange(IReadOnlyList<TContainer> newContainers)

Parameters

newContainers IReadOnlyList<TContainer>

Clear()

Remove all elements in the collection. Does not affect normal child elements.

public void Clear()

Find(Func<TContainer, bool>)

Finds the collection member that meets the conditions required by the predicate.

public TContainer Find(Func<TContainer, bool> predicate)

Parameters

predicate Func<TContainer, bool>

Returns

TContainer

FindIndex(Func<TContainer, bool>)

Finds the index of the collection member that meets the conditions required by the predicate.

public int FindIndex(Func<TContainer, bool> predicate)

Parameters

predicate Func<TContainer, bool>

Returns

int

Insert(int, TContainer)

Adds an element of type TContainer at the given index.

public void Insert(int index, TContainer container)

Parameters

index int
container TContainer

InsertRange(int, IReadOnlyList<TContainer>)

Insert the given range into the collection.

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

Parameters

index int
newContainers IReadOnlyList<TContainer>

Remove(Func<TContainer, bool>)

Removes the collection member that meets the conditions required by the predicate.

public bool Remove(Func<TContainer, bool> predicate)

Parameters

predicate Func<TContainer, bool>

Returns

bool

Remove(TContainer)

Removes the specified element from the collection.

public bool Remove(TContainer collectionElement)

Parameters

collectionElement TContainer

Returns

bool

RemoveAt(int)

Remove the collection element at the given index.

public bool RemoveAt(int index)

Parameters

index int

Returns

bool

RemoveRange(int, int)

Removes the specfied range from the collection. Normal child elements not affected.

public void RemoveRange(int index, int count)

Parameters

index int
count int