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
TContainerContainer element type wrapping the UI element
TElementUI element in the list
TValueValue 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:
- Dropdown<TElement, TValue>: Defaults
TContainerto ListBoxEntry<TElement, TValue>. - Dropdown<TValue>: Defaults
TContainerandTElementto ListBoxEntry<TElement, TValue> and Label, respectively.
Constructors
Dropdown()
public Dropdown()
Dropdown(HudParentBase)
public Dropdown(HudParentBase parent)
Parameters
parentHudParentBase
Properties
BarColor
Color of the slider bar
public Color BarColor { get; set; }
Property Value
BarHighlight
Bar color when moused over
public Color BarHighlight { get; set; }
Property Value
Color
Background color of the dropdown list
public Color Color { get; set; }
Property Value
DropdownHeight
Height of the dropdown list
public float DropdownHeight { get; set; }
Property Value
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
Format
Default format for member text;
public GlyphFormat Format { get; set; }
Property Value
HighlightColor
Background color of the highlight box
public Color HighlightColor { get; set; }
Property Value
HighlightPadding
Padding applied to the highlight box.
public Vector2 HighlightPadding { get; set; }
Property Value
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
LineHeight
Height of entries in the dropdown.
public float LineHeight { get; set; }
Property Value
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
MinVisibleCount
Minimum number of elements visible in the list at any given time.
public int MinVisibleCount { get; set; }
Property Value
MouseInput
Mouse input for the dropdown display.
public IMouseInput MouseInput { get; }
Property Value
Open
Indicates whether or not the list is open.
public bool Open { get; }
Property Value
SelectionIndex
Index of the current selection. -1 if empty.
public int SelectionIndex { get; }
Property Value
SliderColor
Color of the slider box when not moused over
public Color SliderColor { get; set; }
Property Value
SliderHighlight
Color of the slider button when moused over
public Color SliderHighlight { get; set; }
Property Value
TabColor
Color of the highlight box's tab
public Color TabColor { get; set; }
Property Value
UpdateValueCallback
Event initializer utility for SelectionChanged
public EventHandler UpdateValueCallback { set; }
Property Value
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
nameRichTextText to display for this entry
assocMemberTValueValue associated with this entry
enabledboolDetermines 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
entriesIReadOnlyList<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
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
indexintIndex at which to insert the entry
nameRichTextText to display for this entry
assocMemberTValueValue associated with this entry
enabledboolDetermines 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
entryTContainer
Returns
- bool
True if the entry was successfully removed
RemoveAt(int)
Removes the entry at the specified index.
public void RemoveAt(int index)
Parameters
indexint
RemoveRange(int, int)
Removes a range of entries starting from the specified index.
public void RemoveRange(int index, int count)
Parameters
SetSelection(TContainer)
Sets the selection to the specified container object.
public void SetSelection(TContainer member)
Parameters
memberTContainer
SetSelection(TValue)
Sets the selection to the first entry associated with the given value.
public void SetSelection(TValue assocMember)
Parameters
assocMemberTValue
SetSelectionAt(int)
Sets the selection to the entry at the specified index.
public void SetSelectionAt(int index)
Parameters
indexint
Events
ValueChanged
Invoked when a member of the list is selected.
public event EventHandler ValueChanged
Event Type
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.