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

ToggleComponent

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

A selectable line carrying an on/off value.

View source

Constructors

ToggleComponent(string, bool, Action<MenuValueChangedContext<bool>>?, string?)

Creates a toggle.

public ToggleComponent(string text = "", bool defaultValue = false, Action<MenuValueChangedContext<bool>>? onChanged = null, string? id = null)
Parameters
  • textstringoptionalThe label to display.
  • defaultValuebooloptionalThe value a player starts with.
  • onChangedAction<MenuValueChangedContext<bool>>?optionalRuns after the value flips.
  • idstring?optionalA stable id, or null to generate one.

Properties

OffColor

The colour of OffSymbol.

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

OffSymbol

The symbol shown while the value is off.

public string OffSymbol { get; set; }
Property Value

OnColor

The colour of OnSymbol.

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

OnSymbol

The symbol shown while the value is on.

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