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

ChoiceComponent`1

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

A selectable line that cycles through a list one item at a time.

Activating moves forward by one and wraps. For a component that steps both ways with its own keys, use SelectorComponent%601.

View source

Constructors

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

Creates a choice.

public ChoiceComponent(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 cycle 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 value.

public string ClosingBracket { get; set; }
Property Value

ClosingBracketColor

The colour of the closing bracket, or null to keep Style.

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

OpeningBracket

The bracket drawn before the value.

public string OpeningBracket { get; set; }
Property Value

OpeningBracketColor

The colour of the opening bracket, or null to keep Style.

public string? OpeningBracketColor { 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.