Skip to main content

SearchableListDelegate

Trait SearchableListDelegate 

Source
pub trait SearchableListDelegate: Sized + 'static {
    type Item: SearchableListItem;

    // Required methods
    fn items_count(&self, section: usize) -> usize;
    fn item(&self, ix: IndexPath) -> Option<&Self::Item>;
    fn position<V>(&self, _value: &V) -> Option<IndexPath>
       where Self::Item: SearchableListItem<Value = V>,
             V: PartialEq;

    // Provided methods
    fn sections_count(&self, _: &App) -> usize { ... }
    fn section(&self, _section: usize) -> Option<AnyElement> { ... }
    fn perform_search(
        &mut self,
        _query: &str,
        _window: &mut Window,
        _cx: &mut App,
    ) -> Task<()> { ... }
    fn render_item(
        &self,
        _ix: IndexPath,
        _item: &Self::Item,
        _checked: bool,
        _window: &mut Window,
        _cx: &mut App,
    ) -> Option<AnyElement> { ... }
    fn render_section_header(
        &self,
        _section: usize,
        _window: &mut Window,
        _cx: &mut App,
    ) -> Option<AnyElement> { ... }
    fn is_item_enabled(
        &self,
        _ix: IndexPath,
        item: &Self::Item,
        _cx: &App,
    ) -> bool { ... }
    fn is_item_checked(
        &self,
        _ix: IndexPath,
        item: &Self::Item,
        current_selection: &[(IndexPath, Self::Item)],
        _cx: &App,
    ) -> bool { ... }
    fn on_will_change(
        &mut self,
        selection: &mut Vec<(IndexPath, Self::Item)>,
        changes: &[SearchableListChange],
    ) { ... }
    fn on_confirm(&mut self, _final_selection: &[(IndexPath, Self::Item)]) { ... }
}
Expand description

Provides data and search behaviour to a searchable list component.

Required Associated Types§

Required Methods§

Source

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

Number of items in the given section.

Source

fn item(&self, ix: IndexPath) -> Option<&Self::Item>

Return a reference to the item at the given index path.

Source

fn position<V>(&self, _value: &V) -> Option<IndexPath>
where Self::Item: SearchableListItem<Value = V>, V: PartialEq,

Find the index path of the item whose value equals value.

Provided Methods§

Source

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

Number of sections (groups) in the list. Defaults to 1.

Source

fn section(&self, _section: usize) -> Option<AnyElement>

👎Deprecated

Optional header element for the given section index.

Deprecated: override [render_section_header] instead (provides Window + App access).

Called when the search query changes.

Implementations should filter or fetch items and may return an async Task. The App context allows spawning background work.

Source

fn render_item( &self, _ix: IndexPath, _item: &Self::Item, _checked: bool, _window: &mut Window, _cx: &mut App, ) -> Option<AnyElement>

Override the row content for the item at ix.

When Some(_) is returned, the adapter suppresses its default SearchableListItemElement layout (including the automatic trailing check icon) — the returned element is rendered as-is. Return None to fall back to the standard rendering.

checked is true when the item is in the current selection (as determined by is_item_checked), letting custom renderers show their own selection indicator.

Replaces the item_renderer closure that was previously set on SearchableListAdapter.

Source

fn render_section_header( &self, _section: usize, _window: &mut Window, _cx: &mut App, ) -> Option<AnyElement>

Render the header element for the given section (full render access).

When Some(_) is returned, it is rendered directly — the adapter’s default div wrapper (padding, muted colour) is bypassed. Return None to fall back to the deprecated section() wrapped in the standard div (no visual change for existing delegates).

Source

fn is_item_enabled(&self, _ix: IndexPath, item: &Self::Item, _cx: &App) -> bool

Whether the item at ix should be rendered as interactive.

Default: !item.disabled().

Source

fn is_item_checked( &self, _ix: IndexPath, item: &Self::Item, current_selection: &[(IndexPath, Self::Item)], _cx: &App, ) -> bool

Whether the item at ix should show a checkmark.

current_selection is the slice of currently selected (IndexPath, Item) pairs.

Default: checks whether the item’s value is present in current_selection.

Source

fn on_will_change( &mut self, selection: &mut Vec<(IndexPath, Self::Item)>, changes: &[SearchableListChange], )

Called before a user-triggered selection change is committed.

selection is the live selection vec — the delegate may freely mutate it: add items, remove items, reorder, or leave it unchanged to effectively veto the operation.

changes is the slice of atomic changes the mode-strategy computed (e.g. Single replacement deselects all then selects one; Multi toggles the clicked item). The delegate is not required to apply them — they are informational. The default implementation applies every change in order.

No cx is available: this hook runs synchronously during the item-click handler while the list entity is mutably borrowed. Side effects that need cx belong in on_confirm.

Source

fn on_confirm(&mut self, _final_selection: &[(IndexPath, Self::Item)])

Called when the dropdown/popover is committed (Escape, close_on_select, or explicit confirm). final_selection is the selection after the last committed change.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: SearchableListItem + 'static> SearchableListDelegate for Vec<T>

Source§

type Item = T

Source§

fn items_count(&self, _: usize) -> usize

Source§

fn item(&self, ix: IndexPath) -> Option<&Self::Item>

Source§

fn position<V>(&self, value: &V) -> Option<IndexPath>
where Self::Item: SearchableListItem<Value = V>, V: PartialEq,

Implementors§