Skip to main content

ListBuilder

Trait ListBuilder 

Source
pub trait ListBuilder<S: RowSource + 'static>: Sized {
Show 18 methods // Required methods fn row_height(self, h: RowHeight) -> Self; fn on_activate(self, f: impl Fn(S::Ref) + 'static) -> Self; fn on_select(self, f: impl Fn(S::Ref) + 'static) -> Self; fn multi_select(self) -> Self; fn on_selection(self, f: impl Fn(Vec<S::Ref>) + 'static) -> Self; fn selected_rows(self, rows: impl Fn() -> Vec<usize> + 'static) -> Self; fn selection(self, selected: impl Binding<Option<u64>>) -> Self where S::Ref: SelectionKey; fn scroll_to_end(self, trigger: Trigger) -> Self; fn stick_to_bottom(self) -> Self; fn scroll_to_row(self, target: impl Binding<Option<usize>>) -> Self; fn first_visible_row(self, first: impl Binding<usize>) -> Self; fn reorderable(self, reorder: Reorder) -> Self; fn deletable(self, delete: Delete) -> Self; fn swipe_leading( self, provider: impl Fn(usize) -> Vec<SwipeAction> + 'static, ) -> Self; fn swipe_trailing( self, provider: impl Fn(usize) -> Vec<SwipeAction> + 'static, ) -> Self; fn separators(self) -> Self; fn no_separators(self) -> Self; fn editing<M>(self, on: impl IntoReactive<bool, M>) -> Self;
}
Expand description

Builder methods of List, reachable through a Decorated (docs/api-style.md “Typed builders and erasure”): generic modifiers and typed ones chain in any order.

Required Methods§

Source

fn row_height(self, h: RowHeight) -> Self

Row sizing: Uniform(h) (fastest) or Automatic (self-sizing).

Source

fn on_activate(self, f: impl Fn(S::Ref) + 'static) -> Self

Open, play, or otherwise activate a row. Desktop lists use double-click or Enter; touch lists use a tap. Selection callbacks remain independent.

Source

fn on_select(self, f: impl Fn(S::Ref) + 'static) -> Self

Called with the selected row when the native list reports a selection: the key for a plain-data source, the row’s Elem handle for a store source.

Source

fn multi_select(self) -> Self

Allow selecting several rows at once, where the toolkit supports it (docs/list.md has the matrix; single-selection backends fall back to one row at a time). Every selection change calls Self::on_selection with the full set of selected rows.

Source

fn on_selection(self, f: impl Fn(Vec<S::Ref>) + 'static) -> Self

Called with the full set of selected rows (row order, empty = cleared) whenever the selection changes: the multi-select analogue of Self::on_select. Also fired by single-selection backends with a one-element (or empty) set.

Source

fn selected_rows(self, rows: impl Fn() -> Vec<usize> + 'static) -> Self

Reactively sync the native selection to rows (row indices; empty clears). Re-runs whenever the closure’s tracked reads change; the toolkit applies the sync without re-emitting a selection event. Drive it from app state to build “Clear selection”.

Source

fn selection(self, selected: impl Binding<Option<u64>>) -> Self
where S::Ref: SelectionKey,

Two-way single selection by key, for a list of day-model store rows: selected holds the selected row’s key (None for no selection). A row the user picks writes its key, clearing the selection writes None, and a key the app writes selects that row and scrolls it into view, following the row through inserts and moves.

ⓘ
list(scene.items, row_view).selection(scene.selected)
Source

fn scroll_to_end(self, trigger: Trigger) -> Self

Scroll the list so its last row is fully visible whenever trigger fires, e.g. a chat timeline sticking to the newest message. Fire it with day_reactive::Trigger::notify after appending. No-op while the list is empty. The scroll targets the native list (NSTableView/UITableView/GtkListView/QListView/RecyclerView), so it respects the platform’s own scroll physics.

Source

fn stick_to_bottom(self) -> Self

Best-effort auto-stick: after a data reload, scroll to the end so freshly appended rows stay visible. Convenience over Self::scroll_to_end for feeds that always follow the newest row; for finer control (only stick when the user is already near the bottom) drive scroll_to_end from your own logic instead. Off by default.

Source

fn scroll_to_row(self, target: impl Binding<Option<usize>>) -> Self

Programmatic scroll-to-row (docs/list.md): set the signal to Some(row) and the native list scrolls that row into view, realizing it if it was virtualized away: the row rail’s counterpart to scroll(...).scroll_target(...). The signal is left as written; setting the same row again re-fires. Takes a Signal<Option<usize>> or any other binding.

Source

fn first_visible_row(self, first: impl Binding<usize>) -> Self

The first actually visible article/item index, reported by native scrolling into first (a Signal<usize> or any other binding). Use with a heading overlay for floating group headers. No periodic timer is used.

Source

fn reorderable(self, reorder: Reorder) -> Self

Let the user drag rows into a new order (docs/list.md): the list is reorderable exactly when it carries a Reorder, whose handler applies the move to the app’s data.

ⓘ
list(rows, row_view)
    .reorderable(Reorder::new(move |from, to| scene.move_item(from, to)).guard(keep_pinned))
Source

fn deletable(self, delete: Delete) -> Self

Let the user delete rows with the platform’s delete gesture (docs/list.md): the list is deletable exactly when it carries a Delete, whose handler applies the removal to the app’s data.

ⓘ
list(rows, row_view)
    .deletable(Delete::new(move |i| scene.remove_at(i)).label(res::str::delete()))
Source

fn swipe_leading( self, provider: impl Fn(usize) -> Vec<SwipeAction> + 'static, ) -> Self

Offer swipe actions on the row’s leading edge, the reading-direction start, where the platform reveals them as the user drags the row aside (probe Cap::ListSwipeActions; docs/list.md has the matrix; a backend without the affordance shows nothing, so pair each action with an explicit control for the rest). provider runs at gesture time with the row index, so the offer can reflect the row’s current state (“Mark as Read” vs “Mark as Unread”). Keep it pure and fast; it runs inside the platform’s swipe callback; the actions’ handlers run later, at the event drain. A full swipe across activates the edge’s first action.

Source

fn swipe_trailing( self, provider: impl Fn(usize) -> Vec<SwipeAction> + 'static, ) -> Self

Offer swipe actions on the row’s trailing edge, the reading-direction end. Same contract as swipe_leading.

Source

fn separators(self) -> Self

Draw a separator under each row. It is the host’s separator, drawn at the row boundary and never by row content (docs/list.md): it aligns with the native selection and stays put while a macOS/iOS swipe slides the row past it, exactly as Mail’s separators do. Unset, each platform keeps its default (iOS draws them, the desktops don’t); see Self::no_separators for the other override. A backend without a separator mechanism ignores this (the docs matrix says which); don’t re-create the old hand-drawn hairline there. Rows separate by their pitch.

Source

fn no_separators(self) -> Self

Draw no separator between rows, on a platform whose default draws one (iOS).

Source

fn editing<M>(self, on: impl IntoReactive<bool, M>) -> Self

Put the list in the platform’s editing mode (docs/list.md): on iOS, the rows show their delete controls (where a Delete offers one) and reorder grips (where a Reorder moves them), and a tap still activates the row. Reactive, so an Edit/Done button can toggle it, and the change animates.

Probe Cap::ListEditing. The other toolkits have no separate editing mode: their rows drag, swipe and open menus as they are, so the list renders as if this were off.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S: RowSource + 'static, DecoratedInner: ListBuilder<S> + Piece> ListBuilder<S> for Decorated<DecoratedInner>

Source§

impl<S: RowSource + 'static> ListBuilder<S> for List<S>

Day API ↩ Guides· daybrite.dev