Skip to content

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.

Native radio group window with a Reading preferences card, a vertical text-size group, and a horizontal density group
Native SDL_GPU capture of examples/radio_group at Alicorn 47c9d4a. The themed surfaces come from the example theme; the selected dot and focus presentation do not rely on color alone.
Interactive WebGPU preview is a later catalog step. The capture is the real native control; keyboard behavior is documented and tested in the package. The capture predates the parts examples; re-capture is pending.
LayerResponsibility
AlicornLayout, retained nodes, focus, pointer hit testing, Button activation, semantic collection projection, and Radio roles.
radio_groupOption layout, roving index proposal, checked/current presentation, namespaced surface recipe, Press/Focus actions, and one proposed selection event.
ApplicationThe 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.

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.

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.

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).

PartIdentityWhat can be omitted or replaced
Groupgroup_semantic_id(instance_id)Always present; the one Tab stop and Radio_Group collection owner.
Optionoption_semantic_id(instance_id, value)Omit an option by removing it from the slice; remaining identities do not change.
Indicator and labelstable child keys under the option ownerReplace drawing inside the Button owner; keep the semantic item call.
Focus ringactive option while the group owns focusStyle 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.

Recipe declares four optional namespaced surface roles:

FieldCore fallback
item_surface_roleSubtle_Surface
selected_surface_roleSelection
indicator_surface_roleSubtle_Surface
selected_indicator_roleAccent

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.

InputResult
TabReaches the group once. Options are not separate Tab stops.
Up / LeftPrevious enabled option (wraps by default).
Down / RightNext enabled option (wraps by default).
Home / EndFirst/last enabled option.
Space / ReturnPropose the active option.
pointerOrdinary Button activation proposes the clicked option.
semantic PressSame retained Button activation as pointer and keyboard.
  • Selection_Mode.Follow_Focus (default) proposes on arrow movement. Selection_Mode.Activate moves only roving focus; an explicit activation proposes.
  • Disabled options are skipped, do not activate, publish Disabled, and do not advertise Press/Focus.
  • The group publishes Radio_Group, its accessible name, logical option count, selected_id, and current_id. Options publish Radio_Button, label, Checked + Selected when selected, Current when active, and Press + Focus when 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.

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;
  • Activate mode 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.
Terminal window
odin test radio_group -define:ODIN_TEST_THREADS=1 -collection:alicorn=<alicorn> -collection:alikit=.
./out/radio_group_example.exe --smoke

There 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.

DeclarationNotes
Optionvalue, label, description, disabled.
Orientation.Horizontal or .Vertical.
Selection_Mode.Follow_Focus or .Activate.
OptionsAccessible label, orientation, selection mode, item geometry, label size, no_wrap.
Recipe / StyleOptional namespaced surface roles and visual geometry.
StateActive roving value, focus request, and pending proposal.
Group / ItemPer-description parts contexts; Item exposes checked/focused/disabled/position state.
group_begin / item_beginOpen the group and one semantic item; both return a visible flag.
indicator / labelOptional default visual parts.
item_end / group_endClose the item and group; group_end returns the proposal.
Event / Event_KindOne-shot Selection_Proposed carrying value.
radio_groupConvenience wrapper built from the parts.
request_focusFocus the group’s Tab stop after layout.
recipe_default, style_defaultCore-role defaults.
theme_contract_default, theme_contract_check, theme_contract_satisfied, theme_contract_missing_requiredSetup-time validation.
group_semantic_id, option_semantic_idStable semantic identities.
  • 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_key is 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.
Pin: built and captured against Alicorn 47c9d4a7cd1f637876190fec899daeeac00a30ae. See Compatibility and pinning.