Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

RadioGroup

Layer: molecule · Path: src/molecules/radio_group.rs · Exports: radio_group::RadioGroup

A single-select group of Radio atoms bound to a &mut usize index. Composes one labeled radio per option, vertically (default) or horizontally; clicking an option writes its index back into the binding.

Design

  • Purpose / when to use — Pick exactly one option from a short list with full per-option labels visible (vs. a compact ToggleGroup).
  • Anatomy — A vertical or horizontal layout of Radio atoms (Radio::new(selected == i).label(option)), each spaced by SPACE_1.
  • States — exactly one radio reflects *selected == i.
  • Tokens / layout consumedcore::SPACE_1 (inter-option gap). See tokens.

API

MethodEffect
RadioGroup::new(selected: &'a mut usize) -> SelfBind the selected index.
.options<S: Into<String>>(options: impl IntoIterator<Item = S>) -> SelfSet the option labels.
.horizontal() -> SelfLay out in a row instead of a column.
.show(self, ui: &mut Ui) -> ResponseRender; writes *selected = i on click. Returns the layout Response.

Usage

#![allow(unused)]
fn main() {
use ouroboros_ui::molecules::RadioGroup;

// minimal — vertical
let mut sel = 0usize;
RadioGroup::new(&mut sel)
    .options(["Small", "Medium", "Large"])
    .show(ui);
}
#![allow(unused)]
fn main() {
use ouroboros_ui::molecules::RadioGroup;

// horizontal
RadioGroup::new(&mut sel)
    .options(["Windowed", "Fullscreen"])
    .horizontal()
    .show(ui);
}

Composition

Composes Radio atoms inside ui.vertical / ui.horizontal. It never paints — see the guards.

Notes

  • Two-way binding: show mutates *selected to the clicked index.
  • Per-radio ids are derived via .id_source(("radio_group", i)), so a single group is collision-free; nest under FieldSet for a labeled group.
  • Returns the container Response, not a per-option signal — selection is communicated through the binding.