Table of Contents

Class Dropdown<TContainer, TElement, TValue>

Namespace
RichHudFramework.UI
Assembly
RichHudClient.dll

Generic collapsable list box. Allows use of custom entry element types. Designed to mimic the appearance of the dropdown in the SE terminal.

public class Dropdown<TContainer, TElement, TValue> : HudElementBase, IReadOnlyHudElement, IReadOnlyHudNode, IReadOnlyHudParent, IClickableElement, IFocusableElement, IEntryBox<TContainer, TElement>, IEnumerable<TContainer>, IEnumerable, IValueControl<TContainer>, IValueControl where TContainer : class, IListBoxEntry<TElement, TValue>, new() where TElement : HudElementBase, IMinLabelElement

Type Parameters

TContainer

Container element type wrapping the UI element

TElement

UI element in the list

TValue

Value paired with the list entry

Inheritance
Dropdown<TContainer, TElement, TValue>
Implements
IEntryBox<TContainer, TElement>
IEnumerable<TContainer>
IValueControl<TContainer>
Derived
Inherited Members

Examples

var dropdown = new Dropdown<int>(parent)
{
    // Automatically expand to include at least four visible entries at a time, 
    // if there are that many.
    MinVisibleCount = 4,
    UpdateValueCallback = (obj, args) =>
    {
        var sender = (Dropdown<int>)obj;
        MyAPIGateway.Utilities.ShowMessage(
            $"[{sender.GetType().Name}]",
            $"Key: {sender.Value.Element.Text} - Value: {sender.Value.AssocMember}");
    },
    ListContainer =
    {
        { "Label 1", 1234 },
        { new RichText("Label 2", GlyphFormat.White.WithColor(Color.Red)), 4567 },
        { new RichText("Label 3", GlyphFormat.White.WithColor(Color.Green)), 8910 },
        { new RichText("Label 4", GlyphFormat.White.WithColor(Color.GreenYellow)), 1112 },
        { "Label 5", 1314 },
        { "Label 6", 1516 },
        { "Label 7", 1718 },
        { "Label 8", 1920 }
    }
};
var label = new Label(dropdown)
{
    Text = "Dropdown Label",
    ParentAlignment = ParentAlignments.InnerLeft | ParentAlignments.Top
};

Remarks

There are two aliases for Dropdowns used to simplify common usages:

Constructors

Dropdown()

public Dropdown()

Dropdown(HudParentBase)

public Dropdown(HudParentBase parent)

Parameters

parent HudParentBase

Properties

BarColor

Color of the slider bar

public Color BarColor { get; set; }

Property Value

Color

BarHighlight

Bar color when moused over

public Color BarHighlight { get; set; }

Property Value

Color

Color

Background color of the dropdown list

public Color Color { get; set; }

Property Value

Color

DropdownHeight

Height of the dropdown list

public float DropdownHeight { get; set; }

Property Value

float

EntryList

List of entries in the dropdown.

public IReadOnlyList<TContainer> EntryList { get; }

Property Value

IReadOnlyList<TContainer>

FocusHandler

Interface used to manage the element's input focus state

public IFocusHandler FocusHandler { get; }

Property Value

IFocusHandler

Format

Default format for member text;

public GlyphFormat Format { get; set; }

Property Value

GlyphFormat

HighlightColor

Background color of the highlight box

public Color HighlightColor { get; set; }

Property Value

Color

HighlightPadding

Padding applied to the highlight box.

public Vector2 HighlightPadding { get; set; }

Property Value

Vector2

HudCollection

Read-only collection of list entries.

public IReadOnlyHudCollection<TContainer, TElement> HudCollection { get; }

Property Value

IReadOnlyHudCollection<TContainer, TElement>

IsMousedOver

Indicates whether or not the dropdown is moused over.

public override bool IsMousedOver { get; }

Property Value

bool

LineHeight

Height of entries in the dropdown.

public float LineHeight { get; set; }

Property Value

float

ListContainer

Used to allow the addition of list entries using collection-initializer syntax in conjunction with normal initializers.

public Dropdown<TContainer, TElement, TValue> ListContainer { get; }

Property Value

Dropdown<TContainer, TElement, TValue>

MemberPadding

Padding applied to list members.

public Vector2 MemberPadding { get; set; }

Property Value

Vector2

MinVisibleCount

Minimum number of elements visible in the list at any given time.

public int MinVisibleCount { get; set; }

Property Value

int

MouseInput

Mouse input for the dropdown display.

public IMouseInput MouseInput { get; }

Property Value

IMouseInput

Open

Indicates whether or not the list is open.

public bool Open { get; }

Property Value

bool

SelectionIndex

Index of the current selection. -1 if empty.

public int SelectionIndex { get; }

Property Value

int

SliderColor

Color of the slider box when not moused over

public Color SliderColor { get; set; }

Property Value

Color

SliderHighlight

Color of the slider button when moused over

public Color SliderHighlight { get; set; }

Property Value

Color

TabColor

Color of the highlight box's tab

public Color TabColor { get; set; }

Property Value

Color

UpdateValueCallback

Event initializer utility for SelectionChanged

public EventHandler UpdateValueCallback { set; }

Property Value

EventHandler

Value

Current selection. Null if empty.

public TContainer Value { get; }

Property Value

TContainer

Methods

Add(RichText, TValue, bool)

Adds a new entry to the dropdown with the given name, associated value, and enabled state.

public TContainer Add(RichText name, TValue assocMember, bool enabled = true)

Parameters

name RichText

Text to display for this entry

assocMember TValue

Value associated with this entry

enabled bool

Determines if the entry is selectable and visible

Returns

TContainer

AddRange(IReadOnlyList<MyTuple<RichText, TValue, bool>>)

Adds a range of entries to the dropdown from a list of tuples.

public void AddRange(IReadOnlyList<MyTuple<RichText, TValue, bool>> entries)

Parameters

entries IReadOnlyList<MyTuple<RichText, TValue, bool>>

ClearEntries()

Removes all entries from the dropdown.

public void ClearEntries()

ClickDisplay(object, EventArgs)

Handles dropdown display click callback

protected virtual void ClickDisplay(object sender, EventArgs args)

Parameters

sender object
args EventArgs

CloseList()

Collapses the dropdown list and returns focus to the display button

public void CloseList()

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<TContainer> GetEnumerator()

Returns

IEnumerator<TContainer>

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

Insert(int, RichText, TValue, bool)

Inserts a new entry at the specified index.

public void Insert(int index, RichText name, TValue assocMember, bool enabled = true)

Parameters

index int

Index at which to insert the entry

name RichText

Text to display for this entry

assocMember TValue

Value associated with this entry

enabled bool

Determines if the entry is selectable and visible

OpenList()

Expands the dropdown list and captures input focus

public void OpenList()

Remove(TContainer)

Removes the specified container entry from the dropdown.

public bool Remove(TContainer entry)

Parameters

entry TContainer

Returns

bool

True if the entry was successfully removed

RemoveAt(int)

Removes the entry at the specified index.

public void RemoveAt(int index)

Parameters

index int

RemoveRange(int, int)

Removes a range of entries starting from the specified index.

public void RemoveRange(int index, int count)

Parameters

index int
count int

SetSelection(TContainer)

Sets the selection to the specified container object.

public void SetSelection(TContainer member)

Parameters

member TContainer

SetSelection(TValue)

Sets the selection to the first entry associated with the given value.

public void SetSelection(TValue assocMember)

Parameters

assocMember TValue

SetSelectionAt(int)

Sets the selection to the entry at the specified index.

public void SetSelectionAt(int index)

Parameters

index int

Events

ValueChanged

Invoked when a member of the list is selected.

public event EventHandler ValueChanged

Event Type

EventHandler

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.