Skip to main content

Module switcher

Module switcher 

Source
Expand description

Switcher — a container that shows exactly one child page at a time.

Switcher is the fundamental tab/wizard/step primitive: it owns N child pages and exposes only the one whose index matches the Signal<usize> it was constructed with. Switching is a signal write — the framework responds with a relayout that shows the new page and dormantizes all others (excluded from focus traversal, accessibility tree, hit-test, and paint).

Lazy mount. Pages added via child / children / child_boxed stay unconstructed until their index is selected for the first time. Once mounted, the page’s subtree persists for the Switcher’s lifetime — switching away then back finds it in the exact state the user left it (focus, scroll offsets, text-input contents, signal subscriptions). Pages added via child_id are pre-mounted by the caller and treated eagerly.

The Switcher itself reports the maximum natural size across every currently-mounted page and stretches each placed page to its own bounds — all pages share the same slot, so the container size never jumps on a switch.

let page = Signal::new(0_usize);
let _w = Switcher::new(page.clone())
    .child(TextWidget::new(lit!("Step 1")))   // built at startup (index 0 is default)
    .child(TextWidget::new(lit!("Step 2")))   // built on first page.set(1)
    .child(TextWidget::new(lit!("Step 3")));  // built on first page.set(2)

Structs§

Switcher
A container that shows exactly one child at a time, driven by a Signal<usize> index.