跳到正文

Autocomplete

筛选自由输入文本的建议项,无需选中某个值。

#导入

从 quickgui 导入 Autocomplete。

use quickgui::*;

#用法

let mut state = AutocompleteState::new(items);
state.set_query("qui");
div().child(text(state.query()))

#结构

  • Autocomplete::root
  • Autocomplete::input
  • Autocomplete::option_part
  • Autocomplete::label
  • Autocomplete::value
  • Autocomplete::icon
  • Autocomplete::input_group
  • Autocomplete::clear
  • Autocomplete::portal
  • Autocomplete::positioner
  • Autocomplete::popup
  • Autocomplete::arrow
  • Autocomplete::status
  • Autocomplete::empty
  • Autocomplete::list
  • Autocomplete::item
  • Autocomplete::item_indicator
  • Autocomplete::group
  • Autocomplete::group_label
  • Autocomplete::collection
  • Autocomplete::separator

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

AutocompleteState

查看源码
pub fn new(items: impl IntoIterator<Item = PickerItem<T>>) -> Result<Self, PickerError>
with_layoutpub fn with_layout(mut self, layout: AutocompletePopoverLayout) -> Self—

Configures with layout for this part.

pub fn with_layout(mut self, layout: AutocompletePopoverLayout) -> Self
查看源码
with_filter_modepub fn with_filter_mode(mut self, filter_mode: PickerFilterMode) -> Self—

Configures with filter mode for this part.

pub fn with_filter_mode(mut self, filter_mode: PickerFilterMode) -> Self
查看源码
with_filterpub fn with_filter(mut self, filter: PickerFilter) -> Self—

Install an application-supplied filter predicate before a runtime context exists. This is Base UI's `filter` prop. The predicate replaces [`Self::filter_mode`] entirely; [`Self::set_filter`] passing `None` restores it.

pub fn with_filter(mut self, filter: PickerFilter) -> Self
查看源码
with_valuepub fn with_value(mut self, value: impl Into<Arc<str>>) -> Self—

Set the initial free-form value before a runtime context exists. This is the constructor-time equivalent of [`Self::set_value`]: a state that has never been mounted owns no popover to synchronize, so no [`EventContext`] is needed. The value is bounded by [`MAX_AUTOCOMPLETE_VALUE_BYTES`] exactly as it is at runtime.

pub fn with_value(mut self, value: impl Into<Arc<str>>) -> Self
查看源码
layoutpub const fn layout(&self) -> AutocompletePopoverLayout—

Configures layout for this part.

pub const fn layout(&self) -> AutocompletePopoverLayout
查看源码
set_layoutpub fn set_layout(&mut self, layout: AutocompletePopoverLayout, cx: &mut EventContext) -> bool—

Replace native popover geometry, closing an open fixed-size child first.

pub fn set_layout(&mut self, layout: AutocompletePopoverLayout, cx: &mut EventContext) -> bool
查看源码
selection_behaviorpub const fn selection_behavior(&self) -> AutocompleteSelectionBehavior—

Configures selection behavior for this part.

pub const fn selection_behavior(&self) -> AutocompleteSelectionBehavior
查看源码
set_selection_behaviorpub fn set_selection_behavior(&mut self, behavior: AutocompleteSelectionBehavior) -> bool—

Configures set selection behavior for this part.

pub fn set_selection_behavior(&mut self, behavior: AutocompleteSelectionBehavior) -> bool
查看源码
valuepub fn value(&self) -> &Arc<str>—

Configures value for this part.

pub fn value(&self) -> &Arc<str>
查看源码
set_valuepub fn set_value(&mut self, value: impl Into<Arc<str>>, cx: &mut EventContext) -> bool—

Replace the free-form value and recompute or forward the bounded suggestion query.

pub fn set_value(&mut self, value: impl Into<Arc<str>>, cx: &mut EventContext) -> bool
查看源码
itemspub fn items(&self) -> &[PickerItem<T>]—

Configures items for this part.

pub fn items(&self) -> &[PickerItem<T>]
查看源码
set_itemspub fn set_items( &mut self, items: impl IntoIterator<Item = PickerItem<T>>, cx: &mut EventContext, ) -> Result<(), PickerError>—

Atomically replace suggestions and update an open child without reopening its surface.

pub fn set_items( &mut self, items: impl IntoIterator<Item = PickerItem<T>>, cx: &mut EventContext, ) -> Result<(), PickerError>
查看源码
filter_modepub const fn filter_mode(&self) -> PickerFilterMode—

Configures filter mode for this part.

pub const fn filter_mode(&self) -> PickerFilterMode
查看源码
set_filter_modepub fn set_filter_mode( &mut self, filter_mode: PickerFilterMode, cx: &mut EventContext, ) -> bool—

Configures set filter mode for this part.

pub fn set_filter_mode( &mut self, filter_mode: PickerFilterMode, cx: &mut EventContext, ) -> bool
查看源码
filterpub fn filter(&self) -> Option<&PickerFilter>—

The application-supplied filter predicate, when one is installed.

pub fn filter(&self) -> Option<&PickerFilter>
查看源码
set_filterpub fn set_filter(&mut self, filter: Option<PickerFilter>, cx: &mut EventContext) -> bool—

Replace the built-in filter policy with an application-supplied predicate. Passing `None` restores [`Self::filter_mode`]. The open suggestion surface, if any, is resynchronized exactly once.

pub fn set_filter(&mut self, filter: Option<PickerFilter>, cx: &mut EventContext) -> bool
查看源码
popover_windowpub const fn popover_window(&self) -> Option<WindowHandle>—

Configures popover window for this part.

pub const fn popover_window(&self) -> Option<WindowHandle>
查看源码
is_openpub const fn is_open(&self) -> bool—

Configures is open for this part.

pub const fn is_open(&self) -> bool
查看源码
is_disabledpub const fn is_disabled(&self) -> bool—

Configures is disabled for this part.

pub const fn is_disabled(&self) -> bool
查看源码
set_disabledpub fn set_disabled(&mut self, disabled: bool, cx: &mut EventContext) -> bool—

Configures set disabled for this part.

pub fn set_disabled(&mut self, disabled: bool, cx: &mut EventContext) -> bool
查看源码
is_invalidpub const fn is_invalid(&self) -> bool—

Configures is invalid for this part.

pub const fn is_invalid(&self) -> bool
查看源码
set_invalidpub fn set_invalid(&mut self, invalid: bool) -> bool—

Configures set invalid for this part.

pub fn set_invalid(&mut self, invalid: bool) -> bool
查看源码
validation_messagepub fn validation_message(&self) -> Option<&Arc<str>>—

Configures validation message for this part.

pub fn validation_message(&self) -> Option<&Arc<str>>
查看源码
set_validation_messagepub fn set_validation_message(&mut self, message: impl Into<Arc<str>>) -> bool—

Configures set validation message for this part.

pub fn set_validation_message(&mut self, message: impl Into<Arc<str>>) -> bool
查看源码
clear_validation_messagepub fn clear_validation_message(&mut self) -> bool—

Configures clear validation message for this part.

pub fn clear_validation_message(&mut self) -> bool
查看源码
result_countpub fn result_count(&self) -> usize—

Configures result count for this part.

pub fn result_count(&self) -> usize
查看源码
total_match_countpub fn total_match_count(&self) -> usize—

Configures total match count for this part.

pub fn total_match_count(&self) -> usize
查看源码
active_result_indexpub fn active_result_index(&self) -> Option<usize>—

Configures active result index for this part.

pub fn active_result_index(&self) -> Option<usize>
查看源码
active_source_indexpub fn active_source_index(&self) -> Option<usize>—

Configures active source index for this part.

pub fn active_source_index(&self) -> Option<usize>
查看源码
closepub fn close(&mut self, cx: &mut EventContext) -> bool—

Configures close for this part.

pub fn close(&mut self, cx: &mut EventContext) -> bool
查看源码
surface_idpub fn surface_id(id: impl Into<ElementId>) -> ElementId—

Configures surface id for this part.

pub fn surface_id(id: impl Into<ElementId>) -> ElementId
查看源码
option_id_for_sourcepub fn option_id_for_source( &self, id: impl Into<ElementId>, source_index: usize, ) -> Option<ElementId>—

Configures option id for source for this part.

pub fn option_id_for_source( &self, id: impl Into<ElementId>, source_index: usize, ) -> Option<ElementId>
查看源码

AutocompleteState::element

查看源码
pub fn element<V, PopoverRoot, RenderOption, ValueChanged, Select>( &mut self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, label: impl Into<Arc<str>>, access: fn(&mut V) -> &mut AutocompleteState<T>, input: Element, popover_root: PopoverRoot, render_option: RenderOption, value_changed: ValueChanged, select: Select, ) -> Element where V: 'static, T: Clone + 'static, PopoverRoot: Fn(AutocompleteListState) -> Element + Clone + 'static, RenderOption: Fn(&PickerItem<T>, AutocompleteOptionState) -> Element + Clone + 'static, ValueChanged: Fn(&mut V, Arc<str>, &mut EventContext) + Clone + 'static, Select: Fn(&mut V, T, &mut EventContext) + Clone + 'static,

Build the complete unstyled interaction from caller-owned input, popover, and row elements.

AutocompleteState::element_with

查看源码
pub fn element_with<V, PopoverRoot, RenderOption, ValueChanged, Select>( &mut self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, label: impl Into<Arc<str>>, access: StateAccessor<V, AutocompleteState<T>>, input: Element, popover_root: PopoverRoot, render_option: RenderOption, value_changed: ValueChanged, select: Select, ) -> Element where V: 'static, T: Clone + 'static, PopoverRoot: Fn(AutocompleteListState) -> Element + Clone + 'static, RenderOption: Fn(&PickerItem<T>, AutocompleteOptionState) -> Element + Clone + 'static, ValueChanged: Fn(&mut V, Arc<str>, &mut EventContext) + Clone + 'static, Select: Fn(&mut V, T, &mut EventContext) + Clone + 'static,

Build the autocomplete against a per-instance retained-state accessor. A host that renders many declared autocompletes through one view passes an accessor that captures which [`AutocompleteState`] each registered listener resolves.