Skip to content

Implement <RadioGroup> & <Radio> tags (egui::RadioButton / radio_value) #26

@ZhukMax

Description

@ZhukMax

Add radio buttons with a declarative, controlled group API. <RadioGroup value={expr} onChange={|v| ...}> wraps multiple <Radio value="...">Label</Radio> items. Selection is mutually exclusive and updates the bound value.

  • Standard UX for choosing one of several options.
  • Cleaner than wiring multiple RadioButton calls manually.
  • Integrates with forms and settings screens.

Scope

  • New tags: <RadioGroup> and <Radio>.
  • Controlled group: value={expr}, onChange={|v| ...}.
  • Optional attributes: horizontal=bool, enabled, tooltip.
  • <Radio> attributes: value=...; children as label text/inline content.

Proposed API (sketch)

efx!(ui, r#"
<RadioGroup value={prefs.layout} onChange={|v| prefs.layout = v} horizontal="true">
  <Radio value="List">List</Radio>
  <Radio value="Grid">Grid</Radio>
  <Radio value="Compact">Compact</Radio>
</RadioGroup>
"#);

// Mapping (conceptual):
// For each <Radio>: ui.radio_value(&mut group_value, radio_value, label);

Tasks

  • AST for <RadioGroup> / <Radio> and validation (no stray <Radio> outside a group).
  • Codegen: use ui.radio_value(&mut value, item_value, label); emit onChange when value changes.
  • Layout: horizontal=true arranges items in a row; otherwise column.
  • Attributes: enabled, tooltip on group and/or items.
  • Diagnostics: duplicate values; missing value on group or item; nested groups.
  • Examples: layout preference selector; enum-backed group.
  • trybuild UI tests for invalid structures and conflicts.
  • Ensure examples build for wasm32-unknown-unknown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions