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

SelectorComponent`1

Class
Namespace: SwiftlyS2.Shared.Menu.Components · Assembly: SwiftlyS2.CS2.dll
public class SelectorComponent<TItem> : MenuChoiceComponentBase<TItem>, IMenuComponent
Inherits object, MenuComponentBase, TextComponent, MenuValueComponent<int>, MenuChoiceComponentBase<TItem>
Implements IMenuComponent

A selectable line that steps through a list with its own left and right keys.

Takes over NavigateLeft and NavigateRight while it holds the selection, and shows the neighbouring items either side of the current one.

View source

Constructors

SelectorComponent(string, IEnumerable<TItem>?, int, Action<MenuValueChangedContext<TItem>>?, string?)

Creates a selector.

public SelectorComponent(string text = "", IEnumerable<TItem>? choices = null, int defaultIndex = 0, Action<MenuValueChangedContext<TItem>>? onItemChanged = null, string? id = null)
Parameters
  • textstringoptionalThe label to display.
  • choicesIEnumerable<TItem>?optionalThe items to step through.
  • defaultIndexintoptionalThe index a player starts on.
  • onItemChangedAction<MenuValueChangedContext<TItem>>?optionalRuns after the selection moves.
  • idstring?optionalA stable id, or null to generate one.

Properties

ClosingBracket

The bracket drawn after the current item.

public string ClosingBracket { get; set; }
Property Value

NeighbourColor

The colour of the neighbouring items.

public string? NeighbourColor { get; set; }
Property Value

OpeningBracket

The bracket drawn before the current item.

public string OpeningBracket { get; set; }
Property Value

ShowNeighbours

Whether the items either side of the current one are shown.

public bool ShowNeighbours { get; set; }
Property Value

Methods

HandleActionAsync(MenuActionContext)

Offers an action to this component before the menu handles it.

public override ValueTask<bool> HandleActionAsync(MenuActionContext context)
Parameters
Returns
true to consume the action and stop the menu's own handling from running.

Only the focused component is offered actions. Returning true is how a component takes over a key that would otherwise navigate or close the menu.

Render(IMenuComponentRenderContext)

Produces this component's renderer-agnostic output.

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