Radio Group
alikit:radio_group is a controlled compound control for choosing one value from a
small fixed set. It publishes Radio_Group / Radio_Button semantics, one
Tab stop, roving arrow navigation, disabled skipping, and pointer, keyboard, and
assistive-technology activation parity.
Preview
Section titled “Preview”
Responsibility split
Section titled “Responsibility split”| Layer | Responsibility |
|---|---|
| Alicorn | Layout, retained nodes, focus, pointer hit testing, Button activation, semantic collection projection, and Radio roles. |
radio_group | Option layout, roving index proposal, checked/current presentation, namespaced surface recipe, Press/Focus actions, and one proposed selection event. |
| Application | The selected value and mutual exclusion; labels, disabled policy, and domain commands. |
selected_value is an input. State contains only ephemeral interaction state: the active roving
identity, a focus request, and one pending proposal.
Installation
Section titled “Installation”Import the package through the AliKit collection:
import alicorn "alicorn:runtime"import ui "alicorn:ui"import radio "alikit:radio_group"Build with -collection:alikit=<alicorn-kit checkout>. No init or destroy is required; the
component allocates nothing.
To copy the source, copy radio_group/radio_group.odin plus its two intra-AliKit dependencies,
selection/selection.odin and theme_contract/contract.odin (declared under copy in
components.json). Put them in sibling packages and rewrite the two imports in the copied radio
package to import sel "../selection" and import tc "../theme_contract". The copy then builds
with only -collection:alicorn=<alicorn>. Copying radio_group.odin alone does not compile. This
exact copy path is compiled and smoked from a generated external consumer by
tools/validate_external_consumer.ps1.
Copyable implementation
Section titled “Copyable implementation”Files: radio_group/radio_group.odin, selection/selection.odin,
theme_contract/contract.odin, radio_group/radio_group_test.odin,
examples/radio_group/main.odin, examples/radio_group/theme.json.
import alicorn "alicorn:runtime"import ui "alicorn:ui"import radio "alikit:radio_group"
App :: struct { group: radio.State, options: [3]radio.Option, selected: u64,}
render :: proc(app: ^App, ctx: ^ui.UI) { if event := radio.radio_group( ctx, &app.group, app.options[:], app.selected, radio.Options{accessible_label="Text size", orientation=.Vertical}, key=alicorn.key_string("text-size"), instance_id=1, ); event.kind == .Selection_Proposed { app.selected = event.value }}No init or destroy is required; the component allocates nothing. Call
radio.request_focus(&state) when an application interaction should move focus to the group’s
single Tab stop.
Compose the parts
Section titled “Compose the parts”radio_group is a convenience wrapper over the public parts. The same group can be
composed directly; the parts own the Button owner, Radio_Button semantics, roving focus, checked
state, and activation parity, while the author owns everything between item_begin and item_end.
group, visible := radio.group_begin(ctx, &app.group, app.options[:], app.selected, label="Text size", key=alicorn.key_string("size"), instance_id=41)if visible { for option in app.options { item, item_visible := radio.item_begin(ctx, &group, option) if item_visible { radio.indicator(ctx, item) // omit to replace the dot radio.label(ctx, item) // omit for a custom title layout radio.item_end(ctx, item) } } event := radio.group_end(ctx, &group) // one Selection_Proposed, if any}Item exposes option, index, count, checked, focused, focus_visible, disabled, and
visible. An option outside the group’s keyed set returns visible=false and publishes no
semantics. item_begin also accepts an ordinary ui.Layout_Style when the author wants to own the
item’s outer geometry.
Three independently compilable examples cover the paths: the default appearance
(examples/radio_group), radical choice cards with picture/price/description and no default dot
(examples/radio_group_parts), and a dialog-hosted form (examples/radio_group_composition).
Parts and identities
Section titled “Parts and identities”| Part | Identity | What can be omitted or replaced |
|---|---|---|
| Group | group_semantic_id(instance_id) | Always present; the one Tab stop and Radio_Group collection owner. |
| Option | option_semantic_id(instance_id, value) | Omit an option by removing it from the slice; remaining identities do not change. |
| Indicator and label | stable child keys under the option owner | Replace drawing inside the Button owner; keep the semantic item call. |
| Focus ring | active option while the group owns focus | Style width is component-owned. |
Option value 0, a zero instance ID, and duplicate values are invalid. Checked identity follows
the stable value, not the row index. Reordering keeps Checked, Selected, and the active
identity attached to the same value. Removing the active value repairs focus with Alicorn’s pure
roving model: selected value first, else the nearest enabled option, else the first enabled
option.
Styling, motion, and theme
Section titled “Styling, motion, and theme”Recipe declares four optional namespaced surface roles:
| Field | Core fallback |
|---|---|
item_surface_role | Subtle_Surface |
selected_surface_role | Selection |
indicator_surface_role | Subtle_Surface |
selected_indicator_role | Accent |
A zero role needs no theme registration. A configured role is validated once with
theme_contract_default, theme_contract_check, theme_contract_satisfied, and
theme_contract_missing_required. The example registers vendor.alikit.radio_group.* roles
from theme.json; delete that registration to use core roles. The example activates the
registered theme with alicorn.style_environment_push so the extension roles resolve.
Style carries corner radius, indicator radius, and focus-ring width. Options carries
orientation, selection mode, item geometry, and label size. Selection is shown by the filled
radio dot and the selected surface, not by color alone. There is no motion: a radio value change
must be immediately readable.
Keyboard and accessibility contract
Section titled “Keyboard and accessibility contract”| Input | Result |
|---|---|
Tab | Reaches the group once. Options are not separate Tab stops. |
Up / Left | Previous enabled option (wraps by default). |
Down / Right | Next enabled option (wraps by default). |
Home / End | First/last enabled option. |
Space / Return | Propose the active option. |
| pointer | Ordinary Button activation proposes the clicked option. |
semantic Press | Same retained Button activation as pointer and keyboard. |
Selection_Mode.Follow_Focus(default) proposes on arrow movement.Selection_Mode.Activatemoves only roving focus; an explicit activation proposes.- Disabled options are skipped, do not activate, publish
Disabled, and do not advertisePress/Focus. - The group publishes
Radio_Group, its accessible name, logical option count,selected_id, andcurrent_id. Options publishRadio_Button, label,Checked+Selectedwhen selected,Currentwhen active, andPress+Focuswhen enabled. - Focus stays on the group while the active item changes; focus does not follow the pointer into an option.
- Not claimed: multiple selection, a Checkbox contract, type-ahead, or a popup.
Conformance tests
Section titled “Conformance tests”radio_group/radio_group_test.odin drives the package through alicorn:testui:
- semantic roles, parenting, positions,
Checked/Selected/Current, and action presence; - roving Up/Down/Home/End with disabled skipping and wrap;
- keyboard, pointer, and semantic Press proposing the same value;
Activatemode keeping focus and controlled selection separate;- vertical and horizontal appearances preserving identity while changing layout;
- reorder keeping selection attached to the stable value;
- the theme contract reporting configured and missing roles;
- idle: no remaining description or presentation work on the final turn.
odin test radio_group -define:ODIN_TEST_THREADS=1 -collection:alicorn=<alicorn> -collection:alikit=../out/radio_group_example.exe --smokeThere is no testui pattern kind for a radio group at the pinned revision. .Roving_List
requires a List_Box container, while a radio group must publish Radio_Group. A
.Radio_Group pattern is a candidate Alicorn addition; explicit drive assertions are used
instead of claiming a pattern that does not exist.
API reference
Section titled “API reference”| Declaration | Notes |
|---|---|
Option | value, label, description, disabled. |
Orientation | .Horizontal or .Vertical. |
Selection_Mode | .Follow_Focus or .Activate. |
Options | Accessible label, orientation, selection mode, item geometry, label size, no_wrap. |
Recipe / Style | Optional namespaced surface roles and visual geometry. |
State | Active roving value, focus request, and pending proposal. |
Group / Item | Per-description parts contexts; Item exposes checked/focused/disabled/position state. |
group_begin / item_begin | Open the group and one semantic item; both return a visible flag. |
indicator / label | Optional default visual parts. |
item_end / group_end | Close the item and group; group_end returns the proposal. |
Event / Event_Kind | One-shot Selection_Proposed carrying value. |
radio_group | Convenience wrapper built from the parts. |
request_focus | Focus the group’s Tab stop after layout. |
recipe_default, style_default | Core-role defaults. |
theme_contract_default, theme_contract_check, theme_contract_satisfied, theme_contract_missing_required | Setup-time validation. |
group_semantic_id, option_semantic_id | Stable semantic identities. |
Limits
Section titled “Limits”- The component expects a small, caller-owned option slice; it does not virtualize. Use a Select for long lists.
- Label text is single-line with ellipsis overflow. Provide a short label; at the pinned revision a narrower fit-content row can elide more aggressively than the requested item width.
State.active_keyis presentation state; do not persist it as the application’s selection.- Headless tests do not prove a physical screen-reader session, OS high-contrast rendering, or pixels.
Compatibility
Section titled “Compatibility”47c9d4a7cd1f637876190fec899daeeac00a30ae. See
Compatibility and pinning.