SelectionComponentBase`1
Classpublic abstract class SelectionComponentBase<TItem> : MenuComponentBase, IMenuComponent, IMenuRowSourceConstructors
protected SelectionComponentBase(string? id, IEqualityComparer<TItem>? comparer = null)- idstring?A stable id, or null to generate one.
- comparerIEqualityComparer<TItem>?optionalHow items are compared, or null for the default.
Properties
Decides what starts selected, given the session and a candidate, or null to start with nothing. Runs once per session, as soon as the candidates are known, so later arrivals start unselected.
public Func<IMenuSession, TItem, bool>? DefaultSelected { get; set; }The text shown for an item.
public Func<TItem, string> Formatter { get; set; }The most items that can be selected at once, or null for no limit. Extra ticks are ignored.
public int? MaxSelected { get; set; }Runs after an item is ticked or unticked.
public Action<MenuSelectionContext<TItem>>? OnSelectionChanged { get; set; }Draws a row with full control. Takes over from Formatter when set.
public Func<MenuSelectionRowContext<TItem>, MenuNode>? RowRenderer { get; set; }Put before the text of a selected item.
public string SelectedMark { get; set; }The style of a selected row.
public MenuTextStyle SelectedStyle { get; set; }Put before the text of an item that is not selected.
public string UnselectedMark { get; set; }The style of a row that is not selected.
public MenuTextStyle UnselectedStyle { get; set; }Methods
Clears the selection of one session.
public void Clear(IMenuSession session)- sessionIMenuSession
Draws one row for the list underneath.
protected MenuNode DrawRow(IMenuSession session, TItem item, int index, bool isFocused, Func<string, string> translate)The text of an item in the default row. Uses Formatter unless overridden.
protected virtual string FormatText(TItem item, Func<string, string> translate)The rows of the list underneath.
protected abstract IReadOnlyList<IMenuComponent> GetInnerRows(IMenuSession session, MenuRowContext context)- sessionIMenuSession
- contextMenuRowContext
The body entries this component stands for right now.
public IReadOnlyList<IMenuComponent> GetRows(IMenuSession session, MenuRowContext context)- sessionIMenuSessionThe session the rows are for.
- contextMenuRowContextServices the rows need.
The items one session has selected. Items that are gone are dropped.
public IReadOnlyList<TItem> GetSelected(IMenuSession session)- sessionIMenuSession
Whether an item still exists. Gone items are dropped from the selection.
protected virtual bool IsAlive(TItem item)- itemTItem
Whether one session has selected an item.
public bool IsSelected(IMenuSession session, TItem item)- sessionIMenuSession
- itemTItem
Produces this component's renderer-agnostic output.
public override MenuNode Render(IMenuComponentRenderContext context)- contextIMenuComponentRenderContextThe player and focus state to draw for.
Never drawn: the menu replaces this component with MenuRowContext) when it lays out the body.
Replaces the selection of one session.
public void SetSelected(IMenuSession session, IEnumerable<TItem> items)- sessionIMenuSession
- itemsIEnumerable<TItem>
Ticks or unticks an item for the list underneath.
protected void Toggle(IMenuSession session, TItem item)- sessionIMenuSession
- itemTItem
Every item DefaultSelected should be asked about. Return false while they are not known yet.
protected abstract bool TryGetCandidates(IMenuSession session, MenuRowContext context, out IEnumerable<TItem> candidates)- sessionIMenuSession
- contextMenuRowContext
- candidatesIEnumerable<TItem>
Raised when MenuRowContext) would return something different.
public event Action? RowsChanged