Skip to main content

Module radio_button

Module radio_button 

Source
Expand description

RadioButton — mutually exclusive selection control.

Multiple RadioButtons share a Signal<usize>; selecting one writes its value to the signal, which automatically deselects every sibling that observes the same signal. The widget is non-generic: values are usize indices into the caller’s choice list. Wrap related buttons in a RadioGroup to provide the AT “2 of 3” positional announcement required by ARIA.

§Label styling

The label is Body / Primary and the caption Small / Secondary by default. RadioButton::label_style / RadioButton::label_color and RadioButton::caption_style / RadioButton::caption_color override them. A theme role colour still dims when the button is disabled; a literal Color stays as given.

§Touch and pen

Same shape as Checkbox: the pressed state is the framework’s (docs/touch-and-pen.md §7.1), selection lands on the release, and the 24 dp MinSize around the 19 dp dot already clears the conformance floor at Compact.

§Accessibility

Reports Role::RadioButton with set_toggled mirroring the selected state. Responds to Action::Click from assistive technology. The focus ring is keyboard-only (:focus-visible gated by the input-modality signal). When wrapped in RadioGroup, each button emits push_to_radio_group([sibling_ids]) so screen readers can announce positional membership.

let selected = Signal::new(0_usize);
let _r0 = RadioButton::new(0, selected.clone()).label(lit!("Light"));
let _r1 = RadioButton::new(1, selected.clone()).label(lit!("Dark"));
let _r2 = RadioButton::new(2, selected.clone()).label(lit!("System"));

Structs§

RadioButton
A single radio button option that writes value into a shared Signal<usize> on selection.