ToggleSwitch class Core

An on/off switch: a pill track with a sliding knob and its label beside it, for a setting that takes effect at once (a check box is for a choice confirmed later). Behaves like CheckBox: release-over and Space/Enter flip it through the same endpoint, a focused screen-reader user hears the new state.

Styling. From the style sheets (Select.Type<ToggleSwitch>()): the track when off (background) and on (accent colour), the label's colour, size, weight and family, and the opacity, in every state.

public sealed class ToggleSwitch : Control
Namespace
ArionUI.Presentation.Controls
Package
ArionUI.Presentation · dotnet add package ArionUI.Presentation --prerelease
Inherits
Control

Constructors

ToggleSwitch

public ToggleSwitch();

Properties

Cursor

public override GridCursor Cursor { get; }

DrawsOwnFocus

public override bool DrawsOwnFocus { get; }

The control shows its focus itself (accent border, hover row, ring parameter). False = the host draws the shared default ring around Control.Bounds.

Focusable

public override bool Focusable { get; }

Can this KIND of control hold the keyboard focus? Combined with the live probes in Control.CanTakeFocus.

MeasureText

public Func<string, TextStyle, double>? MeasureText { get; init; }

How wide the label is drawn; with it the switch measures its own width.

Role

public override ControlRole Role { get; }

What KIND of part this is for assistive technology — the automation peers translate it into their host's control type.

Text

public required Func<string> Text { get; init; }

Toggle

public required Action Toggle { get; init; }

ToggleState

public override bool? ToggleState { get; }

The checked state of a toggle part; null when the part does not toggle.

Value

public required Func<bool> Value { get; init; }

WantsTick

public override bool WantsTick { get; }

The control animates and wants Control.Tick on every frame.

Methods

Invoke

public override bool Invoke();

Act like a click on the part (a button fires, a checkbox flips, a menu row runs, a dropdown opens). False when the part has no action or is disabled.

Measure

public override LogSize Measure(LogSize available);

Desired size given the space available (layout containers sum this).

OnKey

public override bool OnKey(ArionKey key, ArionModifiers mods);

Keys while focused. Return false to let the pane's fallback see the key.

OnPointerReleased

public override void OnPointerReleased(LogPoint p);

Render

public override void Render(IRenderSurface s, ControlFrame frame);

SpokenLabel

public override string? SpokenLabel();

What a screen reader speaks when this control receives the focus. A control that cannot take the focus but answers here is READ: it becomes a text part.

Tick

public override void Tick(double dtMs);

One frame of the animation. What it changes on screen it marks itself (Control.Invalidate): on a board only the marked area is drawn again.