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
TThe 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
groupRadioGroup<T>The coordinating group that owns the single-selection invariant.
valueTThe value this radio represents.
labelstringThe 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
CanFocusWithMouse
Gets whether the radio can receive focus via mouse click. Only can focus when enabled.
public bool CanFocusWithMouse { get; }
Property Value
CanReceiveFocus
Whether this control can receive focus
public bool CanReceiveFocus { get; }
Property Value
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
CheckmarkColor
Gets or sets the color of the mark character when selected.
public Color CheckmarkColor { get; set; }
Property Value
ColorRole
The semantic color role. Default = no role (normal resolution).
public ColorRole ColorRole { get; set; }
Property Value
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
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
DisabledForegroundColor
Gets or sets the foreground color when the control is disabled.
public Color DisabledForegroundColor { get; set; }
Property Value
FocusedBackgroundColor
Gets or sets the background color when the control has focus.
public Color? FocusedBackgroundColor { get; set; }
Property Value
FocusedForegroundColor
Gets or sets the foreground color when the control has focus.
public Color FocusedForegroundColor { get; set; }
Property Value
ForegroundColor
Gets or sets the foreground color of the radio in its normal state.
public Color ForegroundColor { get; set; }
Property Value
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
IsEnabled
Gets or sets whether the radio is enabled and can be interacted with.
public bool IsEnabled { get; set; }
Property Value
Label
Gets or sets the label text displayed next to the radio.
public string Label { get; set; }
Property Value
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
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
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
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
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
Methods
MeasureDOM(LayoutConstraints)
Measures the control's desired size given the available constraints.
public override LayoutSize MeasureDOM(LayoutConstraints constraints)
Parameters
constraintsLayoutConstraintsThe 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
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
ProcessKey(ConsoleKeyInfo)
Processes a keyboard input event.
public bool ProcessKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfoThe 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
argsMouseEventArgs
Returns
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
MouseDoubleClick
Occurs when the radio is double-clicked with the mouse.
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Occurs when the mouse enters the radio area.
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Occurs when the mouse leaves the radio area.
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Occurs when the mouse moves over the radio.
public event EventHandler<MouseEventArgs>? MouseMove
Event Type
MouseRightClick
Occurs when the radio is right-clicked with the mouse.
public event EventHandler<MouseEventArgs>? MouseRightClick