Components / data
List builder
A list that renders only the rows its viewport holds.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::data::List;
Also drawn by deferred-drop, which arranges components rather than reviewing them.
Construct
new(ident: impl Into<Ident>, count: usize, render_row: impl Fn(usize, &mut Window, &mut App) -> ListItem + 'static) -> Self
Options
Chain onto the value.
selected(id: impl Into<SharedString>) -> Self
row_height(height: f32) -> Self
flowing() -> Self
anchored_to_end() -> Self
keys(keys: impl IntoIterator<Item = impl Into<SharedString>>) -> Self
revisions(revisions: Vec<u64>) -> Self
visible_rows(rows: usize) -> Self
fills() -> Self
arriving() -> Self
on_select(handler: impl Fn(SharedString, &mut Window, &mut App) + 'static) -> Self
reorderable(reorderable: bool) -> Self
accepts(predicate: impl Fn(&DragItem, &DropPosition) -> bool + 'static) -> Self
deferred_acceptance(controller: dnd::DeferredDrop, revision: u64) -> Self
on_reorder(handler: impl Fn(&DropIntent, &mut Window, &mut App) + 'static) -> Self
Example · list
fn list(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
stack(&theme)
.w(px(420.0))
.child(
crate::foundation::text(
&theme,
TypeScale::Caption,
SharedString::from(format!(
"{FIXTURE_RECORDS} fixture records; only the rendered ones publish"
)),
)
.text_tone(&theme, TextTone::Muted),
)
.child(
div()
.surface(&theme, Surface::Panel)
.radius(&theme, Radius::Card)
.py_token(&theme, Space::Sm)
.overflow_hidden()
.child(
List::new("scene.list.records", FIXTURE_RECORDS, |index, _, _| {
let (id, label) = fixture_record(index);
ListItem::new(id, label.clone()).text(label)
})
.selected(fixture_record(2).0)
.visible_rows(8)
.on_select(|_, _, _| {}),
),
)
.into_any_element()
}
Source: crates/gpui-kit/src/data/list.rs