swiftlys2/docs/api/releases/features/ai/
API Reference › Menu.Components

SelectionComponentBase`1

Class
Namespace: SwiftlyS2.Shared.Menu.Components · Assembly: SwiftlyS2.CS2.dll
public abstract class SelectionComponentBase<TItem> : MenuComponentBase, IMenuComponent, IMenuRowSource
View source

Constructors

SelectionComponentBase(string?, IEqualityComparer<TItem>?)

protected SelectionComponentBase(string? id, IEqualityComparer<TItem>? comparer = null)
Parameters
  • idstring?A stable id, or null to generate one.
  • comparerIEqualityComparer<TItem>?optionalHow items are compared, or null for the default.

Properties

DefaultSelected

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; }
Property Value

Formatter

The text shown for an item.

public Func<TItem, string> Formatter { get; set; }
Property Value
Func<TItem, string>

MaxSelected

The most items that can be selected at once, or null for no limit. Extra ticks are ignored.

public int? MaxSelected { get; set; }
Property Value

OnSelectionChanged

Runs after an item is ticked or unticked.

public Action<MenuSelectionContext<TItem>>? OnSelectionChanged { get; set; }
Property Value
Action<MenuSelectionContext<TItem>>?

RowRenderer

Draws a row with full control. Takes over from Formatter when set.

public Func<MenuSelectionRowContext<TItem>, MenuNode>? RowRenderer { get; set; }
Property Value
Func<MenuSelectionRowContext<TItem>, MenuNode>?

SelectedMark

Put before the text of a selected item.

public string SelectedMark { get; set; }
Property Value

SelectedStyle

The style of a selected row.

public MenuTextStyle SelectedStyle { get; set; }
Property Value

UnselectedMark

Put before the text of an item that is not selected.

public string UnselectedMark { get; set; }
Property Value

UnselectedStyle

The style of a row that is not selected.

public MenuTextStyle UnselectedStyle { get; set; }
Property Value

Methods

Clear(IMenuSession)

Clears the selection of one session.

public void Clear(IMenuSession session)
Parameters

DrawRow(IMenuSession, TItem, int, bool, Func<string, string>)

Draws one row for the list underneath.

protected MenuNode DrawRow(IMenuSession session, TItem item, int index, bool isFocused, Func<string, string> translate)
Parameters
Returns

FormatText(TItem, Func<string, string>)

The text of an item in the default row. Uses Formatter unless overridden.

protected virtual string FormatText(TItem item, Func<string, string> translate)
Parameters
Returns

GetInnerRows(IMenuSession, MenuRowContext)

The rows of the list underneath.

protected abstract IReadOnlyList<IMenuComponent> GetInnerRows(IMenuSession session, MenuRowContext context)
Parameters

GetRows(IMenuSession, MenuRowContext)

The body entries this component stands for right now.

public IReadOnlyList<IMenuComponent> GetRows(IMenuSession session, MenuRowContext context)
Parameters

GetSelected(IMenuSession)

The items one session has selected. Items that are gone are dropped.

public IReadOnlyList<TItem> GetSelected(IMenuSession session)
Parameters
Returns

IsAlive(TItem)

Whether an item still exists. Gone items are dropped from the selection.

protected virtual bool IsAlive(TItem item)
Parameters
  • itemTItem
Returns

IsSelected(IMenuSession, TItem)

Whether one session has selected an item.

public bool IsSelected(IMenuSession session, TItem item)
Parameters
Returns

RaiseRowsChanged()

Raises RowsChanged.

protected void RaiseRowsChanged()

Render(IMenuComponentRenderContext)

Produces this component's renderer-agnostic output.

public override MenuNode Render(IMenuComponentRenderContext context)
Parameters
Returns
The nodes describing this component.

Never drawn: the menu replaces this component with MenuRowContext) when it lays out the body.

SetSelected(IMenuSession, IEnumerable<TItem>)

Replaces the selection of one session.

public void SetSelected(IMenuSession session, IEnumerable<TItem> items)
Parameters

Toggle(IMenuSession, TItem)

Ticks or unticks an item for the list underneath.

protected void Toggle(IMenuSession session, TItem item)
Parameters

TryGetCandidates(IMenuSession, MenuRowContext, out IEnumerable<TItem>)

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)
Parameters
Returns

RowsChanged

Raised when MenuRowContext) would return something different.

public event Action? RowsChanged
Value