Autocomplete
筛选自由输入文本的建议项,无需选中某个值。
#导入
从 quickgui 导入 Autocomplete。
use quickgui::*;#用法
let mut state = AutocompleteState::new(items);
state.set_query("qui");
div().child(text(state.query()))#结构
Autocomplete::rootAutocomplete::inputAutocomplete::option_partAutocomplete::labelAutocomplete::valueAutocomplete::iconAutocomplete::input_groupAutocomplete::clearAutocomplete::portalAutocomplete::positionerAutocomplete::popupAutocomplete::arrowAutocomplete::statusAutocomplete::emptyAutocomplete::listAutocomplete::itemAutocomplete::item_indicatorAutocomplete::groupAutocomplete::group_labelAutocomplete::collectionAutocomplete::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—
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>—
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>]—
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—
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—
is_disabledpub 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—
set_invalidpub 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—
total_match_countpub fn total_match_count(&self) -> usize—
active_result_indexpub fn active_result_index(&self) -> Option<usize>—
active_source_indexpub fn active_source_index(&self) -> Option<usize>—
closepub fn close(&mut self, cx: &mut EventContext) -> bool—
surface_idpub 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.
