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

ButtonComponent

Class
Namespace: SwiftlyS2.Shared.Menu.Components · Assembly: SwiftlyS2.CS2.dll
public class ButtonComponent : TextComponent, IMenuComponent

A selectable line that runs a callback when activated.

Activation goes through the shared pipeline, so Validating can veto it and a slow OnSelect cannot be started twice by the same player.

View source

Constructors

ButtonComponent(string, Func<MenuActionContext, ValueTask>?, string?)

Creates a button.

public ButtonComponent(string text = "", Func<MenuActionContext, ValueTask>? onSelect = null, string? id = null)
Parameters

Properties

CloseOnSelect

Whether activating the button also closes the menu.

public bool CloseOnSelect { get; set; }
Property Value

FocusedColor

The colour applied when the button is focused, or null to keep Style.

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

IsFocusable

Whether the selection can land on this component.

public override bool IsFocusable { get; }
Property Value

A label can hold the selection like any other body entry, so a menu scrolls past it rather than skipping over it, but it never overrides MenuActionContext) so activating it is always a no-op.

OnSelect

Runs when the button is activated.

public Func<MenuActionContext, ValueTask>? OnSelect { get; set; }

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.

ResolveStyle(IMenuComponentRenderContext)

Resolves the style to draw with, accounting for the disabled state.

protected override MenuTextStyle ResolveStyle(IMenuComponentRenderContext context)
Parameters
Returns
The style to use.