Table of Contents

Class RadioControl<T>

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A single radio option whose selection is coordinated by a RadioGroup<T>. Mirrors CheckboxControl but its Checked state is computed from the group (the group is the single source of truth), guaranteeing the single-selection invariant. Supports keyboard interaction with Space or Enter keys to select.

public class RadioControl<T> : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable, IColorRoleableControl

Type Parameters

T

The value type this radio represents.

Inheritance
RadioControl<T>
Implements
Inherited Members
Extension Methods

Constructors

RadioControl(RadioGroup<T>, T, string)

Initializes a new instance of the RadioControl<T> class and registers it with the group.

public RadioControl(RadioGroup<T> group, T value, string label = "")

Parameters

group RadioGroup<T>

The coordinating group that owns the single-selection invariant.

value T

The value this radio represents.

label string

The text label displayed next to the radio.

Properties

BackgroundColor

Gets or sets the background color of the radio in its normal state.

public Color? BackgroundColor { get; set; }

Property Value

Color?

CanFocusWithMouse

Gets whether the radio can receive focus via mouse click. Only can focus when enabled.

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

Checked

Gets a value indicating whether this radio is the group's selected option. Computed from the group (no stored state), so it always reflects the single-selection invariant.

public bool Checked { get; }

Property Value

bool

CheckmarkColor

Gets or sets the color of the mark character when selected.

public Color CheckmarkColor { get; set; }

Property Value

Color

ColorRole

The semantic color role. Default = no role (normal resolution).

public ColorRole ColorRole { get; set; }

Property Value

ColorRole

ColorRoleMode

Optional ThemeMode override for role-colour derivation. When non-null, the role's dark/light seed colours are resolved as if the theme were in this mode, regardless of the theme's own Mode. When null (the default), the active theme's mode is used.

public ThemeMode? ColorRoleMode { get; set; }

Property Value

ThemeMode?

ContentWidth

Gets the actual rendered width of the control based on content.

public override int? ContentWidth { get; }

Property Value

int?

DisabledBackgroundColor

Gets or sets the background color when the control is disabled.

public Color? DisabledBackgroundColor { get; set; }

Property Value

Color?

DisabledForegroundColor

Gets or sets the foreground color when the control is disabled.

public Color DisabledForegroundColor { get; set; }

Property Value

Color

FocusedBackgroundColor

Gets or sets the background color when the control has focus.

public Color? FocusedBackgroundColor { get; set; }

Property Value

Color?

FocusedForegroundColor

Gets or sets the foreground color when the control has focus.

public Color FocusedForegroundColor { get; set; }

Property Value

Color

ForegroundColor

Gets or sets the foreground color of the radio in its normal state.

public Color ForegroundColor { get; set; }

Property Value

Color

Group

Gets the coordinating group that owns the single-selection invariant.

public RadioGroup<T> Group { get; }

Property Value

RadioGroup<T>

HasFocus

public bool HasFocus { get; }

Property Value

bool

IsEnabled

Gets or sets whether the radio is enabled and can be interacted with.

public bool IsEnabled { get; set; }

Property Value

bool

Label

Gets or sets the label text displayed next to the radio.

public string Label { get; set; }

Property Value

string

Outline

When true and a role is set, renders outline style (role color on text + border, surface fill).

public bool Outline { get; set; }

Property Value

bool

SelectedCharacter

Gets or sets the character displayed inside the radio when selected. Defaults to "●". Empty or null values fall back to the default.

public string SelectedCharacter { get; set; }

Property Value

string

UnselectedCharacter

Gets or sets the character displayed inside the radio when unselected. Defaults to "○". Empty or null values fall back to the default.

public string UnselectedCharacter { get; set; }

Property Value

string

Value

Gets the value this radio represents.

public T Value { get; }

Property Value

T

WantsMouseEvents

Gets whether the radio wants to receive mouse events. Only receives events when enabled.

public bool WantsMouseEvents { get; }

Property Value

bool

Wrap

Gets or sets a value indicating whether the label wraps across lines when too wide to fit. (Wrap geometry is applied by the paint pass; single-line rendering is used until then.)

public bool Wrap { get; set; }

Property Value

bool

Methods

MeasureDOM(LayoutConstraints)

Measures the control's desired size given the available constraints.

public override LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

The layout constraints (min/max width/height).

Returns

LayoutSize

The desired size of the control.

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)

Parameters

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultFg Color
defaultBg Color

ProcessKey(ConsoleKeyInfo)

Processes a keyboard input event.

public bool ProcessKey(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo

The key information for the pressed key.

Returns

bool

True if the key was handled by this control; otherwise, false.

ProcessMouseEvent(MouseEventArgs)

Processes mouse events for the radio. Handles clicks to select this option and capture focus.

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Returns

bool

Select()

Selects this radio through the group. If this radio is already the selected one, the group's deselect/Required policy applies (classic radios stay selected).

public void Select()

Events

MouseClick

Occurs when the radio is clicked with the mouse.

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Occurs when the radio is double-clicked with the mouse.

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Occurs when the mouse enters the radio area.

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Occurs when the mouse leaves the radio area.

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Occurs when the mouse moves over the radio.

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>

MouseRightClick

Occurs when the radio is right-clicked with the mouse.

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>