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

SliderComponent

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

A selectable line carrying a number, drawn as a bar.

Takes over NavigateLeft and NavigateRight while it holds the selection; activating steps up by one Step.

View source

Constructors

SliderComponent(string, float, float, float?, float, Action<MenuValueChangedContext<float>>?, string?)

Creates a slider.

public SliderComponent(string text = "", float min = 0, float max = 100, float? defaultValue = null, float step = 5, Action<MenuValueChangedContext<float>>? onChanged = null, string? id = null)
Parameters
  • textstringoptionalThe label to display.
  • minfloatoptionalThe lowest value.
  • maxfloatoptionalThe highest value.
  • defaultValuefloat?optionalThe value a player starts with, or null for min .
  • stepfloatoptionalHow far one press moves the value.
  • onChangedAction<MenuValueChangedContext<float>>?optionalRuns after the value changes.
  • idstring?optionalA stable id, or null to generate one.

Properties

ClosingBracket

The bracket drawn after the bar.

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

EmptyChar

The character drawn for an empty segment.

public string EmptyChar { get; set; }
Property Value

EmptyColor

The colour of the empty segments.

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

FilledChar

The character drawn for a filled segment.

public string FilledChar { get; set; }
Property Value

Max

The highest value.

public float Max { get; set; }
Property Value

Min

The lowest value.

public float Min { get; set; }
Property Value

OpeningBracket

The bracket drawn before the bar.

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

ShowValue

Whether the number itself is shown next to the bar.

public bool ShowValue { get; set; }
Property Value

Step

How far one press moves the value. Never zero or negative.

public float Step { get; set; }
Property Value

TotalBars

How many segments the bar is drawn with. Never below one.

public int TotalBars { get; set; }
Property Value

ValueFormat

How the number is formatted.

public string ValueFormat { get; set; }
Property Value

WrapAround

Whether stepping past either end continues from the other.

public bool WrapAround { get; set; }
Property Value

Methods

Coerce(IMenuSession, float)

Adjusts a value before it is stored.

protected override float Coerce(IMenuSession session, float value)
Parameters
  • sessionIMenuSessionThe session the value belongs to.
  • valuefloatThe value being stored.
Returns
The value to store.

Used for clamping into a range or into the bounds of a list.

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.

StepValue(IMenuSession, int)

Moves this player's value by one Step.

public bool StepValue(IMenuSession session, int direction)
Parameters
  • sessionIMenuSessionThe session to move.
  • directionintPositive to step up, negative to step down.
Returns
true when the value changed.