pub struct List<T: 'static = (), K: 'static = (), R = RowRender<T>> { /* private fields */ }Expand description
A virtualised list of rows, shown by the platform’s own list control.
List::new(move || contacts.get(), |c| c.id, |c| ContactRow(c))
.selected(selected) // Signal<Vec<K>>: the selected keys
.on_activate(|id| open(id)) // double-click or Enter
.grow(1.0)Only the rows the platform shows (in view, or about to be) are mounted; the others exist only as their keys. Rows can hold any view. Each row is laid out at the width the list gives its rows, and is as high as its content.
Rows are read by screen readers (and found by tests) as list items named by their text.
The type’s defaults make List alone name the widget, for
Tweak<List>.
Implementations§
Source§impl<T: 'static, K: 'static, R> List<T, K, R>
impl<T: 'static, K: 'static, R> List<T, K, R>
Sourcepub fn on_move(
self,
moves: RowMoves,
handler: impl Fn(Vec<K>, RowDrop<K>) + 'static,
) -> Self
pub fn on_move( self, moves: RowMoves, handler: impl Fn(Vec<K>, RowDrop<K>) + 'static, ) -> Self
Rows can be dragged within the list, with the platform’s own row
drag (the selection, when a selected row is dragged), and dropped
where moves says: onto a row, between rows, or both. handler
gets the rows, in the list’s order, and where they were dropped
(RowDrop: onto a row, before one, or at the end). The list shows
nothing moved: the app moves its data, or leaves it. Dragging isn’t
reachable from the keyboard or assistive technology: offer another
way too (a Move command).
List::new(..).on_move(RowMoves::onto_rows(), |ids, to| move_into(ids, to))Sourcepub fn drag_files(self, file: impl Fn(&T) -> Option<PathBuf> + 'static) -> Self
pub fn drag_files(self, file: impl Fn(&T) -> Option<PathBuf> + 'static) -> Self
Rows can be dragged out of the app, carrying the files their items
stand for (None: that row doesn’t drag), to the file manager,
another app or a folder, as a file manager’s rows are: the
platform’s own drag, which drags the selected rows when a selected
one is dragged. The drag offers to copy, so the files stay where
they are. Dragging isn’t reachable from the keyboard or assistive
technology, so offer another way too (Copy, Share, Export).
List::new(..).drag_files(|entry: &Entry| Some(entry.path.clone()))Sourcepub fn selected(self, selected: Signal<Vec<K>>) -> Self
pub fn selected(self, selected: Signal<Vec<K>>) -> Self
Binds the selection, as the selected rows’ keys, both ways. Lists
with a selection bound select one row at a time unless
selection_mode says otherwise.
Sourcepub fn selection_mode(self, mode: impl IntoValue<SelectionMode>) -> Self
pub fn selection_mode(self, mode: impl IntoValue<SelectionMode>) -> Self
How many rows can be selected. It can change while the list shows: the selection keeps what the new mode can hold (none, or the row the platform keeps), and the rows let go are reported as deselected.
Sourcepub fn list_style(self, style: ListStyle) -> Self
pub fn list_style(self, style: ListStyle) -> Self
How the list sits in its surroundings: edge to edge (the default) or
framed. Pick per platform with platform!:
List::new(..).list_style(platform! { kde => ListStyle::Framed, _ => ListStyle::Plain })Sourcepub fn on_activate(self, handler: impl Fn(K) + 'static) -> Self
pub fn on_activate(self, handler: impl Fn(K) + 'static) -> Self
Called with a row’s key when it’s activated: double-clicked, or Enter pressed on it.
Sourcepub fn on_key(
self,
key: impl Into<Shortcut>,
handler: impl Fn() + 'static,
) -> Self
pub fn on_key( self, key: impl Into<Shortcut>, handler: impl Fn() + 'static, ) -> Self
Runs handler when key is pressed while the list, or a control
inside it, has keyboard focus, and the focused control doesn’t use
the key itself (the arrows, Home and End, typing to
select, and what else the platform’s list takes): Space for a preview, Delete for Move to Trash.
A key goes to the nearest node around the focused control that
takes it. Nothing shows keys taken this way, so give the command a
menu item or a button too, and pick the keys the platform’s own apps
use (platform!).
List::new(..).on_key(' ', preview)Sourcepub fn estimated_row_height(self, height: impl Into<Length>) -> Self
pub fn estimated_row_height(self, height: impl Into<Length>) -> Self
How high rows are likely to be, for platforms that size rows before they’re shown (AppKit). By default, the rows shown so far tell.
Sourcepub fn handle(self, handle: ListHandle<K>) -> Self
pub fn handle(self, handle: ListHandle<K>) -> Self
Connects a ListHandle, to scroll the list from code.
Sourcepub fn native(self, tweak: Tweak<List>) -> Self
pub fn native(self, tweak: Tweak<List>) -> Self
Raw platform settings: see Tweak. They run on the list view,
not the scroll view around it. Lists have no semantic options past
their rows, selection and style: what the platforms offer
(alternating rows on AppKit, separators on GTK, key navigation on Qt
and WinUI) is each one’s own.
Trait Implementations§
Source§impl<T: 'static, K: 'static, R> ElementBuilder for List<T, K, R>
impl<T: 'static, K: 'static, R> ElementBuilder for List<T, K, R>
fn element(&mut self) -> &mut Element
Source§fn style(self, f: impl FnOnce(&mut Style)) -> Self
fn style(self, f: impl FnOnce(&mut Style)) -> Self
Source§fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self
fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self
f re-runs whenever the
signals it reads change, and must set every field it cares about.fn width(self, value: impl IntoValue<Length>) -> Self
fn height(self, value: impl IntoValue<Length>) -> Self
fn min_width(self, value: impl IntoValue<Length>) -> Self
fn min_height(self, value: impl IntoValue<Length>) -> Self
fn max_width(self, value: impl IntoValue<Length>) -> Self
fn max_height(self, value: impl IntoValue<Length>) -> Self
fn aspect_ratio(self, value: impl IntoValue<f32>) -> Self
fn padding(self, value: impl IntoValue<Length>) -> Self
fn padding_x(self, value: impl IntoValue<Length>) -> Self
fn padding_y(self, value: impl IntoValue<Length>) -> Self
fn padding_start(self, value: impl IntoValue<Length>) -> Self
fn padding_end(self, value: impl IntoValue<Length>) -> Self
fn padding_top(self, value: impl IntoValue<Length>) -> Self
fn padding_bottom(self, value: impl IntoValue<Length>) -> Self
fn margin(self, value: impl IntoValue<Length>) -> Self
fn margin_x(self, value: impl IntoValue<Length>) -> Self
fn margin_y(self, value: impl IntoValue<Length>) -> Self
fn margin_start(self, value: impl IntoValue<Length>) -> Self
fn margin_end(self, value: impl IntoValue<Length>) -> Self
fn margin_top(self, value: impl IntoValue<Length>) -> Self
fn margin_bottom(self, value: impl IntoValue<Length>) -> Self
fn grow(self, value: impl IntoValue<f32>) -> Self
fn shrink(self, value: impl IntoValue<f32>) -> Self
fn basis(self, value: impl IntoValue<Length>) -> Self
fn align_self(self, value: impl IntoValue<Align>) -> Self
Source§fn justify_self(self, value: impl IntoValue<Align>) -> Self
fn justify_self(self, value: impl IntoValue<Align>) -> Self
Source§fn top(self, value: impl IntoValue<Length>) -> Self
fn top(self, value: impl IntoValue<Length>) -> Self
absolute()).fn bottom(self, value: impl IntoValue<Length>) -> Self
Source§fn start(self, value: impl IntoValue<Length>) -> Self
fn start(self, value: impl IntoValue<Length>) -> Self
fn end(self, value: impl IntoValue<Length>) -> Self
fn grid_column(self, value: impl IntoValue<GridPlacement>) -> Self
fn grid_row(self, value: impl IntoValue<GridPlacement>) -> Self
fn direction(self, value: impl IntoValue<TextDirection>) -> Self
display the node had.fn size( self, width: impl IntoValue<Length>, height: impl IntoValue<Length>, ) -> Self
Source§fn tooltip(self, text: impl IntoValue<String>) -> Self
fn tooltip(self, text: impl IntoValue<String>) -> Self
entries, and built again whenever what it
reads changes, as Menu::children_with builds its entries.entries each time the platform opens it,
for a menu that depends on what’s selected or under the pointer at
that moment: a table row’s menu acting on the selection. What it
reads is read then, not followed.