Skip to main content

keyed

Function keyed 

Source
pub fn keyed<State: 'static, V: View<State>>(
    key: impl Into<ChildKey>,
    view: V,
) -> FlexChild<State>
Expand description

An inflexible child tagged with a stable ChildKey, for a list whose items reorder, insert, or delete between frames.

Attaching a key to any child opts the whole FlexView into keyed reconciliation: on the next rebuild, children are matched to their live widgets by key rather than by position, so a shuffled or grown list preserves each surviving row’s widget and its internal state (a scroll offset, a text buffer, a toggle) instead of rebuilding whatever now sits at that index. Keys are all-or-nothing per list and must be unique within it (see ChildKey).

Use it inside FlexView::new alongside (or instead of) inflexible:

use frust_widgets::{Axis, FlexView, keyed, text};
FlexView::new(
    Axis::Vertical,
    items.iter().map(|item| keyed(item.id, text(item.label.clone()))).collect(),
)

v1 keyed children are inflexible; combining a key with a flex factor is a future extension.