Skip to main content

ListDelegate

Trait ListDelegate 

Source
pub trait ListDelegate: Sized + 'static {
    type Item: Selectable + IntoElement;

Show 16 methods // Required methods fn items_count(&self, section: usize, cx: &App) -> usize; fn render_item( &mut self, ix: IndexPath, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> Option<Self::Item>; fn set_selected_index( &mut self, ix: Option<IndexPath>, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ); // Provided methods fn perform_search( &mut self, query: &str, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> Task<()> { ... } fn sections_count(&self, cx: &App) -> usize { ... } fn render_section_header( &mut self, section: usize, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> Option<impl IntoElement> { ... } fn render_section_footer( &mut self, section: usize, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> Option<impl IntoElement> { ... } fn render_empty( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> impl IntoElement { ... } fn render_initial( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> Option<AnyElement> { ... } fn loading(&self, cx: &App) -> bool { ... } fn render_loading( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> impl IntoElement { ... } fn confirm( &mut self, secondary: bool, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) { ... } fn cancel( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) { ... } fn is_eof(&self, cx: &App) -> bool { ... } fn load_more_threshold(&self) -> usize { ... } fn load_more( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) { ... }
}
Expand description

A delegate for the List.

Required Associated Types§

Required Methods§

Source

fn items_count(&self, section: usize, cx: &App) -> usize

Return the number of items in the section at the given index.

Source

fn render_item( &mut self, ix: IndexPath, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> Option<Self::Item>

Render the item at the given index.

Return None will skip the item.

NOTE: Every item should have same height.

Source

fn set_selected_index( &mut self, ix: Option<IndexPath>, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, )

Set the selected index, just store the ix, don’t confirm.

Provided Methods§

When Query Input change, this method will be called. You can perform search here.

Source

fn sections_count(&self, cx: &App) -> usize

Return the number of sections in the list, default is 1.

Source

fn render_section_header( &mut self, section: usize, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> Option<impl IntoElement>

Render the section header at the given index, default is None.

NOTE: Every header should have same height.

Render the section footer at the given index, default is None.

NOTE: Every footer should have same height.

Source

fn render_empty( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> impl IntoElement

Return a Element to show when list is empty.

Source

fn render_initial( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> Option<AnyElement>

Returns Some(AnyElement) to render the initial state of the list.

This can be used to show a view for the list before the user has interacted with it.

For example: The last search results, or the last selected item.

Default is None, that means no initial state.

Source

fn loading(&self, cx: &App) -> bool

Returns the loading state to show the loading view.

Source

fn render_loading( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, ) -> impl IntoElement

Returns a Element to show when loading, default is built-in Skeleton loading view.

Source

fn confirm( &mut self, secondary: bool, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, )

Set the confirm and give the selected index, this is means user have clicked the item or pressed Enter.

This will always to set_selected_index before confirm.

Source

fn cancel(&mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>)

Cancel the selection, e.g.: Pressed ESC.

Source

fn is_eof(&self, cx: &App) -> bool

Return true to enable load more data when scrolling to the bottom.

Default: true

Source

fn load_more_threshold(&self) -> usize

Returns a threshold value (n entities), of course, when scrolling to the bottom, the remaining number of rows triggers load_more.

This should smaller than the total number of first load rows.

Default: 20 entities (section header, footer and row)

Source

fn load_more( &mut self, window: &mut Window, cx: &mut Context<'_, ListState<Self>>, )

Load more data when the table is scrolled to the bottom.

This will performed in a background task.

This is always called when the table is near the bottom, so you must check if there is more data to load or lock the loading state.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§