Skip to main content

PickerState

Struct PickerState 

Source
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>

Source

pub fn new( items: impl IntoIterator<Item = PickerItem<T>>, ) -> Result<Self, PickerError>

Source

pub fn with_layout(self, layout: PickerLayout) -> Self

Source

pub const fn layout(&self) -> PickerLayout

Source

pub fn set_layout(&mut self, layout: PickerLayout) -> bool

Source

pub fn set_items( &mut self, items: impl IntoIterator<Item = PickerItem<T>>, ) -> Result<(), PickerError>

Source

pub fn items(&self) -> &[PickerItem<T>]

Source

pub const fn filter_mode(&self) -> PickerFilterMode

Source

pub fn set_filter_mode(&mut self, filter_mode: PickerFilterMode) -> bool

Source

pub fn filter(&self) -> Option<&PickerFilter>

The custom predicate replacing Self::filter_mode, when one is installed.

Source

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.

Source

pub fn item_at(&self, source_index: usize) -> Option<&PickerItem<T>>

Source

pub fn source_index_for_id(&self, id: impl Into<ElementId>) -> Option<usize>

Source

pub fn query(&self) -> &Arc<str> ⓘ

Source

pub fn set_query(&mut self, query: &str) -> bool

Replace the controlled query and recompute the bounded ranked result set.

Source

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.

Source

pub fn result_count(&self) -> usize

Source

pub fn total_match_count(&self) -> usize

Source

pub fn results_truncated(&self) -> bool

Source

pub fn selected_result_index(&self) -> Option<usize>

Source

pub fn selected_source_index(&self) -> Option<usize>

Source

pub fn match_at(&self, result_index: usize) -> Option<PickerMatch<'_, T>>

Source

pub fn selected_match(&self) -> Option<PickerMatch<'_, T>>

Source

pub fn selected_value(&self) -> Option<&T>

Source

pub fn visible_matches(&self) -> impl Iterator<Item = PickerMatch<'_, T>> + '_

Source

pub fn virtual_list(&self) -> &VirtualList

Source

pub fn select_result(&mut self, result_index: usize) -> bool

Source

pub fn select_source(&mut self, source_index: usize) -> bool

Source

pub fn select_next(&mut self) -> bool

Source

pub fn select_previous(&mut self) -> bool

Source

pub fn select_first(&mut self) -> bool

Source

pub fn select_last(&mut self) -> bool

Source

pub fn select_page_down(&mut self) -> bool

Source

pub fn select_page_up(&mut self) -> bool

Source

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.

Source

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, ) -> Element
where 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.

Source

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, ) -> Element
where 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§

Source§

impl<T> Debug for PickerState<T>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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>
where Arc<[PickerItem<T>]>: Freeze,

§

impl<T> Unpin for PickerState<T>
where Arc<[PickerItem<T>]>: Unpin,

§

impl<T> UnsafeUnpin for PickerState<T>
where Arc<[PickerItem<T>]>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more