pub struct PickerState<T> { /* private fields */ }Expand description
Retained fuzzy matches, keyboard selection, and virtual-scroll state for a picker.
Matching runs only when source items or the controlled query change. Results and search text are hard-bounded; scrolling and hover reuse the framework’s retained list and paint paths.
Implementations§
Source§impl<T> PickerState<T>
impl<T> PickerState<T>
pub fn new( items: impl IntoIterator<Item = PickerItem<T>>, ) -> Result<Self, PickerError>
pub fn with_layout(self, layout: PickerLayout) -> Self
pub const fn layout(&self) -> PickerLayout
pub fn set_layout(&mut self, layout: PickerLayout) -> bool
pub fn set_items( &mut self, items: impl IntoIterator<Item = PickerItem<T>>, ) -> Result<(), PickerError>
pub fn items(&self) -> &[PickerItem<T>]
pub const fn filter_mode(&self) -> PickerFilterMode
pub fn set_filter_mode(&mut self, filter_mode: PickerFilterMode) -> bool
Sourcepub fn filter(&self) -> Option<&PickerFilter>
pub fn filter(&self) -> Option<&PickerFilter>
The custom predicate replacing Self::filter_mode, when one is installed.
Sourcepub fn set_filter(&mut self, filter: Option<PickerFilter>) -> bool
pub fn set_filter(&mut self, filter: Option<PickerFilter>) -> bool
Replace the built-in filter mode with an application-supplied predicate.
Passing None restores Self::filter_mode. The result set is rebuilt exactly once.
pub fn item_at(&self, source_index: usize) -> Option<&PickerItem<T>>
pub fn source_index_for_id(&self, id: impl Into<ElementId>) -> Option<usize>
pub fn query(&self) -> &Arc<str> ⓘ
Sourcepub fn set_query(&mut self, query: &str) -> bool
pub fn set_query(&mut self, query: &str) -> bool
Replace the controlled query and recompute the bounded ranked result set.
Sourcepub fn reset(&mut self) -> bool
pub fn reset(&mut self) -> bool
Clear the query, restore source-order matches, select the first enabled item, and scroll back to the beginning. Command palettes normally call this each time they open.
pub fn result_count(&self) -> usize
pub fn total_match_count(&self) -> usize
pub fn results_truncated(&self) -> bool
pub fn selected_result_index(&self) -> Option<usize>
pub fn selected_source_index(&self) -> Option<usize>
pub fn match_at(&self, result_index: usize) -> Option<PickerMatch<'_, T>>
pub fn selected_match(&self) -> Option<PickerMatch<'_, T>>
pub fn selected_value(&self) -> Option<&T>
pub fn visible_matches(&self) -> impl Iterator<Item = PickerMatch<'_, T>> + '_
pub fn virtual_list(&self) -> &VirtualList
pub fn select_result(&mut self, result_index: usize) -> bool
pub fn select_source(&mut self, source_index: usize) -> bool
pub fn select_next(&mut self) -> bool
pub fn select_previous(&mut self) -> bool
pub fn select_first(&mut self) -> bool
pub fn select_last(&mut self) -> bool
pub fn select_page_down(&mut self) -> bool
pub fn select_page_up(&mut self) -> bool
Sourcepub fn input_focus_handle(id: impl Into<ElementId>) -> FocusHandle
pub fn input_focus_handle(id: impl Into<ElementId>) -> FocusHandle
Stable focus handle for the search input derived from a picker surface identity.
This may be passed to EventContext::focus in the same event that mounts the picker;
QuickGUI carries the request through that one retained-tree rebuild.
Sourcepub fn element<V, E, RenderRow, Activate>(
&mut self,
cx: &mut ViewContext<'_, V>,
id: impl Into<ElementId>,
label: impl Into<Arc<str>>,
access: fn(&mut V) -> &mut PickerState<T>,
input: Element,
empty: Element,
render_row: RenderRow,
activate: Activate,
) -> Elementwhere
V: 'static,
T: Clone + 'static,
E: IntoElement,
RenderRow: FnMut(PickerMatch<'_, T>) -> E,
Activate: Fn(&mut V, T, &mut EventContext) + Clone + 'static,
pub fn element<V, E, RenderRow, Activate>(
&mut self,
cx: &mut ViewContext<'_, V>,
id: impl Into<ElementId>,
label: impl Into<Arc<str>>,
access: fn(&mut V) -> &mut PickerState<T>,
input: Element,
empty: Element,
render_row: RenderRow,
activate: Activate,
) -> Elementwhere
V: 'static,
T: Clone + 'static,
E: IntoElement,
RenderRow: FnMut(PickerMatch<'_, T>) -> E,
Activate: Fn(&mut V, T, &mut EventContext) + Clone + 'static,
Build a complete unstyled uniform-row picker from caller-owned elements.
input, empty, and every value returned by render_row keep their declared layout and
appearance. QuickGUI adds only stable identity, bounded virtual positioning, input/action
listeners, selection/disabled semantics, and activation behavior. The returned root is
also unpainted and can be extended with caller-owned status content before mounting.
access identifies this state inside the owning view when an event arrives. activate
receives a clone of the selected value, so the picker can close and restore focus before
dispatching an application command without retaining a borrow into view state.
Sourcepub fn element_with<V, E, RenderRow, Activate>(
&mut self,
cx: &mut ViewContext<'_, V>,
id: impl Into<ElementId>,
label: impl Into<Arc<str>>,
access_source: StateAccessor<V, PickerState<T>>,
input: Element,
empty: Element,
render_row: RenderRow,
activate: Activate,
) -> Elementwhere
V: 'static,
T: Clone + 'static,
E: IntoElement,
RenderRow: FnMut(PickerMatch<'_, T>) -> E,
Activate: Fn(&mut V, T, &mut EventContext) + Clone + 'static,
pub fn element_with<V, E, RenderRow, Activate>(
&mut self,
cx: &mut ViewContext<'_, V>,
id: impl Into<ElementId>,
label: impl Into<Arc<str>>,
access_source: StateAccessor<V, PickerState<T>>,
input: Element,
empty: Element,
render_row: RenderRow,
activate: Activate,
) -> Elementwhere
V: 'static,
T: Clone + 'static,
E: IntoElement,
RenderRow: FnMut(PickerMatch<'_, T>) -> E,
Activate: Fn(&mut V, T, &mut EventContext) + Clone + 'static,
Build the picker against a per-instance retained-state accessor.
A host that renders many declared pickers through one view passes an accessor that captures
which PickerState each registered listener resolves.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for PickerState<T>
impl<T> !Send for PickerState<T>
impl<T> !Sync for PickerState<T>
impl<T> !UnwindSafe for PickerState<T>
impl<T> Freeze for PickerState<T>
impl<T> Unpin for PickerState<T>
impl<T> UnsafeUnpin for PickerState<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.