Select
单选或多选选择器,选项界面显示在原生浮窗中。
#导入
从 quickgui 导入 Select。
use quickgui::*;#用法
let mut state = SelectState::new(items);
state.open(true);
div().child(text(state.selected_label().unwrap_or("Choose")))#结构
Select::rootSelect::triggerSelect::option_partSelect::labelSelect::valueSelect::iconSelect::backdropSelect::portalSelect::positionerSelect::popupSelect::arrowSelect::listSelect::itemSelect::item_textSelect::item_indicatorSelect::groupSelect::group_labelSelect::separatorSelect::scroll_up_arrowSelect::scroll_down_arrow
#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
SelectState
查看源码pub fn new(items: impl IntoIterator<Item = PickerItem<T>>) -> Result<Self, PickerError>with_layoutpub fn with_layout(mut self, layout: SelectPopoverLayout) -> Self—
Configures with layout for this part.
pub fn with_layout(mut self, layout: SelectPopoverLayout) -> Self查看源码layoutpub fn layout(&self) -> SelectPopoverLayout—
set_layoutpub fn set_layout(&mut self, layout: SelectPopoverLayout) -> bool—
Configures set layout for this part.
pub fn set_layout(&mut self, layout: SelectPopoverLayout) -> bool查看源码itemspub fn items(&self) -> &[PickerItem<T>]—
from_labelspub fn from_labels( items: impl IntoIterator<Item = (T, impl Into<Arc<str>>)>, ) -> Result<Self, PickerError>—
Create a select from Base UI's `items` map form, one entry per value and its label. This is the shortest declaration for a select whose options are a fixed value-to-label mapping; [`Self::new`] stays available for options that need stable IDs or disabled rows.
pub fn from_labels( items: impl IntoIterator<Item = (T, impl Into<Arc<str>>)>, ) -> Result<Self, PickerError>查看源码selected_source_indexpub fn selected_source_index(&self) -> Option<usize>—
The first selected source index, or `None` when nothing is selected.
pub fn selected_source_index(&self) -> Option<usize>查看源码selected_source_indicespub fn selected_source_indices(&self) -> &[usize]—
Every selected source index, ascending, Base UI's `multiple` value array. A single select holds at most one entry; a multiple select holds at most [`MAX_SELECT_VALUES`].
pub fn selected_source_indices(&self) -> &[usize]查看源码selected_itemspub fn selected_items(&self) -> impl Iterator<Item = &PickerItem<T>>—
Every selected item, in source order.
pub fn selected_items(&self) -> impl Iterator<Item = &PickerItem<T>>查看源码selected_valuespub fn selected_values(&self) -> impl Iterator<Item = &T>—
value_textpub fn value_text(&self) -> Option<Arc<str>>—
The joined label text a trigger shows, Base UI's `Select.Value`. Returns `None` when nothing is selected, which is when Base UI renders the placeholder.
pub fn value_text(&self) -> Option<Arc<str>>查看源码value_separatorpub fn value_separator(mut self, separator: impl Into<Arc<str>>) -> Self—
Replace the separator joining a multiple select's value text.
pub fn value_separator(mut self, separator: impl Into<Arc<str>>) -> Self查看源码multiplepub fn multiple(mut self, multiple: bool) -> Self—
Accept more than one value, Base UI's `multiple`. Turning `multiple` off keeps only the first selected value, so the retained set can never disagree with the declared arity.
pub fn multiple(mut self, multiple: bool) -> Self查看源码set_multiplepub fn set_multiple(&mut self, multiple: bool) -> bool—
Replace the multiple flag in place, reporting whether anything changed.
pub fn set_multiple(&mut self, multiple: bool) -> bool查看源码is_multiplepub const fn is_multiple(&self) -> bool—
requiredpub const fn required(mut self, required: bool) -> Self—
Require a value before submission, Base UI's `required`.
pub const fn required(mut self, required: bool) -> Self查看源码is_requiredpub const fn is_required(&self) -> bool—
read_onlypub const fn read_only(mut self, read_only: bool) -> Self—
Refuse value changes while staying focusable, Base UI's `readOnly`.
pub const fn read_only(mut self, read_only: bool) -> Self查看源码is_read_onlypub const fn is_read_only(&self) -> bool—
modalpub const fn modal(mut self, modal: bool) -> Self—
Contain focus and expect a mounted backdrop while open, Base UI's `modal`.
pub const fn modal(mut self, modal: bool) -> Self查看源码is_modalpub const fn is_modal(&self) -> bool—
align_item_with_triggerpub const fn align_item_with_trigger(mut self, align: bool) -> Self—
Open the popup so the selected row overlaps the trigger, Base UI's `alignItemWithTrigger`. QuickGUI offsets the anchored surface by the selected row's distance from the top of the popup plus [`SelectPopoverLayout::trigger_height`], so the row the user is already looking at does not move under the pointer. The native surface still resolves the final side against the display work area.
pub const fn align_item_with_trigger(mut self, align: bool) -> Self查看源码aligns_item_with_triggerpub const fn aligns_item_with_trigger(&self) -> bool—
Configures aligns item with trigger for this part.
pub const fn aligns_item_with_trigger(&self) -> bool查看源码set_pressedpub const fn set_pressed(&mut self, pressed: bool) -> bool—
Record that the trigger is held down, Base UI's `data-pressed`.
pub const fn set_pressed(&mut self, pressed: bool) -> bool查看源码set_focusedpub const fn set_focused(&mut self, focused: bool) -> bool—
Record trigger focus, and mark the control touched when focus leaves it.
pub const fn set_focused(&mut self, focused: bool) -> bool查看源码mark_touchedpub const fn mark_touched(&mut self) -> bool—
Mark the control as having been interacted with, Base UI's `data-touched`.
pub const fn mark_touched(&mut self) -> bool查看源码reset_touchedpub const fn reset_touched(&mut self) -> bool—
Forget that the control was interacted with, for a form that has just been reset. This is the counterpart of [`Self::reset_dirty`]: a value applied from a declaration is not an interaction, so a host that seeds the control reports Base UI's `data-touched` only for what the user really did.
pub const fn reset_touched(&mut self) -> bool查看源码reset_dirtypub const fn reset_dirty(&mut self) -> bool—
Forget that the value changed, for a form that has just been submitted or reset.
pub const fn reset_dirty(&mut self) -> bool查看源码is_dirtypub const fn is_dirty(&self) -> bool—
is_touchedpub const fn is_touched(&self) -> bool—
is_focusedpub const fn is_focused(&self) -> bool—
statepub fn state(&self) -> SelectPartState—
A copyable render-state snapshot the application styles from.
pub fn state(&self) -> SelectPartState查看源码selected_itempub fn selected_item(&self) -> Option<&PickerItem<T>>—
selected_valuepub fn selected_value(&self) -> Option<&T>—
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—
is_invalidpub const fn is_invalid(&self) -> bool—
set_itemspub fn set_items( &mut self, items: impl IntoIterator<Item = PickerItem<T>>, cx: &mut EventContext, ) -> Result<(), PickerError>—
Replace the complete bounded source atomically and close an obsolete open snapshot.
pub fn set_items( &mut self, items: impl IntoIterator<Item = PickerItem<T>>, cx: &mut EventContext, ) -> Result<(), PickerError>查看源码select_sourcepub fn select_source(&mut self, source_index: usize) -> bool—
Select one source row. A single select replaces its value. A multiple select adds the row, up to [`MAX_SELECT_VALUES`]. A read-only select refuses both.
pub fn select_source(&mut self, source_index: usize) -> bool查看源码toggle_sourcepub fn toggle_source(&mut self, source_index: usize) -> bool—
Toggle one source row, Base UI's `multiple` item behavior. A single select clears its value when the already-selected row is chosen again; a multiple select removes just that value.
pub fn toggle_source(&mut self, source_index: usize) -> bool查看源码is_source_selectedpub fn is_source_selected(&self, source_index: usize) -> bool—
Whether one source row is currently selected.
pub fn is_source_selected(&self, source_index: usize) -> bool查看源码select_idpub fn select_id(&mut self, id: impl Into<ElementId>) -> bool—
Configures select id for this part.
pub fn select_id(&mut self, id: impl Into<ElementId>) -> bool查看源码clear_selectionpub fn clear_selection(&mut self) -> bool—
set_disabledpub fn set_disabled(&mut self, disabled: bool, cx: &mut EventContext) -> bool—
Change disabled state and synchronously request closure of an open native popover.
pub fn set_disabled(&mut self, disabled: bool, cx: &mut EventContext) -> 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查看源码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>查看源码label_idpub fn label_id(id: impl Into<ElementId>) -> ElementId—
Stable identity of the mounted label part.
pub fn label_id(id: impl Into<ElementId>) -> ElementId查看源码value_idpub fn value_id(id: impl Into<ElementId>) -> ElementId—
Stable identity of the mounted value part.
pub fn value_id(id: impl Into<ElementId>) -> ElementId查看源码icon_idpub fn icon_id(id: impl Into<ElementId>) -> ElementId—
backdrop_idpub fn backdrop_id(id: impl Into<ElementId>) -> ElementId—
Stable identity of the optional owner-window backdrop.
pub fn backdrop_id(id: impl Into<ElementId>) -> ElementId查看源码arrow_idpub fn arrow_id(id: impl Into<ElementId>) -> ElementId—
Stable identity of the decorative popup arrow.
pub fn arrow_id(id: impl Into<ElementId>) -> ElementId查看源码list_idpub fn list_id(id: impl Into<ElementId>) -> ElementId—
Stable identity of the scrolling option list inside the popup.
pub fn list_id(id: impl Into<ElementId>) -> ElementId查看源码scroll_up_arrow_idpub fn scroll_up_arrow_id(id: impl Into<ElementId>) -> ElementId—
Stable identity of the upward scroll affordance.
pub fn scroll_up_arrow_id(id: impl Into<ElementId>) -> ElementId查看源码scroll_down_arrow_idpub fn scroll_down_arrow_id(id: impl Into<ElementId>) -> ElementId—
Stable identity of the downward scroll affordance.
pub fn scroll_down_arrow_id(id: impl Into<ElementId>) -> ElementId查看源码SelectState::root_with
查看源码pub fn root_with(root: Element) -> ElementDecorate the optional application-owned structural wrapper, Base UI's `Select.Root`.
SelectState::root
查看源码pub fn root() -> ElementCreate the unstyled root part. Use [`Self::root_with`] to supply an existing element.
SelectState::label_with
查看源码pub fn label_with(id: impl Into<ElementId>, label: Element) -> ElementDecorate the caller-owned visible label, Base UI's `Select.Label`. [`Self::trigger_with`] points at this identity, so the label names the control without its text being copied into a second accessible string.
SelectState::label
查看源码pub fn label(id: impl Into<ElementId>) -> ElementCreate the unstyled label part. Use [`Self::label_with`] to supply an existing element.
SelectState::value_with
查看源码pub fn value_with(id: impl Into<ElementId>, value: Element) -> ElementDecorate the caller-owned value text inside the trigger, Base UI's `Select.Value`. The trigger already exposes the selected value, so this part is hidden from assistive technology and would otherwise be announced twice. Render [`Self::value_text`] inside it, or the placeholder when it returns `None`.
SelectState::value
查看源码pub fn value(id: impl Into<ElementId>) -> ElementCreate the unstyled value part. Use [`Self::value_with`] to supply an existing element.
SelectState::icon_with
查看源码pub fn icon_with(id: impl Into<ElementId>, icon: Element) -> ElementDecorate the caller-owned trigger affordance, Base UI's `Select.Icon`.
SelectState::icon
查看源码pub fn icon(id: impl Into<ElementId>) -> ElementCreate the unstyled icon part. Use [`Self::icon_with`] to supply an existing element.
SelectState::backdrop_with
查看源码pub fn backdrop_with(id: impl Into<ElementId>, backdrop: Element) -> ElementDecorate an optional caller-painted owner-window backdrop, Base UI's `Select.Backdrop`. The option surface is a separate native child window that already takes the pointer grab, so this layer exists only for a caller-painted dimming pass. Mount it while [`Self::is_open`] is true, and declare [`Self::modal`] so the intent is inspectable.
SelectState::backdrop
查看源码pub fn backdrop(id: impl Into<ElementId>) -> ElementCreate the unstyled backdrop part. Use [`Self::backdrop_with`] to supply an existing element.
SelectState::portal_with
查看源码pub fn portal_with( id: impl Into<ElementId>, label: impl Into<Arc<str>>, option_count: usize, multiple: bool, portal: Element, ) -> ElementDecorate the popup boundary, Base UI's `Select.Portal` and `Select.Positioner`. QuickGUI's option surface is its own native window, so the portal, the positioner, and the popup are one element: all three names decorate it identically and QuickGUI resolves its placement against the display work area rather than a parent stacking context.
SelectState::portal
查看源码pub fn portal( id: impl Into<ElementId>, label: impl Into<Arc<str>>, option_count: usize, multiple: bool, ) -> ElementCreate the unstyled portal part. Use [`Self::portal_with`] to supply an existing element.
SelectState::positioner_with
查看源码pub fn positioner_with( id: impl Into<ElementId>, label: impl Into<Arc<str>>, option_count: usize, multiple: bool, positioner: Element, ) -> ElementDecorate the popup boundary, Base UI's `Select.Positioner`.
SelectState::positioner
查看源码pub fn positioner( id: impl Into<ElementId>, label: impl Into<Arc<str>>, option_count: usize, multiple: bool, ) -> ElementCreate the unstyled positioner part. Use [`Self::positioner_with`] to supply an existing element.
SelectState::popup_with
查看源码pub fn popup_with( id: impl Into<ElementId>, label: impl Into<Arc<str>>, option_count: usize, multiple: bool, popup: Element, ) -> ElementDecorate the caller-owned option surface, Base UI's `Select.Popup`. QuickGUI applies this to whatever the surface renderer returns, so an application that composes its own in-window list can reuse exactly the semantics the native surface gets.
SelectState::popup
查看源码pub fn popup( id: impl Into<ElementId>, label: impl Into<Arc<str>>, option_count: usize, multiple: bool, ) -> ElementCreate the unstyled popup part. Use [`Self::popup_with`] to supply an existing element.
SelectState::arrow_with
查看源码pub fn arrow_with(id: impl Into<ElementId>, arrow: Element) -> ElementPosition a caller-owned decorative arrow, Base UI's `Select.Arrow`.
SelectState::arrow
查看源码pub fn arrow(id: impl Into<ElementId>) -> ElementCreate the unstyled arrow part. Use [`Self::arrow_with`] to supply an existing element.
SelectState::list_with
查看源码pub fn list_with(id: impl Into<ElementId>, option_count: usize, list: Element) -> ElementDecorate the caller-owned scrolling option list, Base UI's `Select.List`. The popup already carries the list-box role, so the inner list is a structural container: it keeps a stable identity and the declared set size without announcing a second list.
SelectState::list
查看源码pub fn list(id: impl Into<ElementId>, option_count: usize) -> ElementCreate the unstyled list part. Use [`Self::list_with`] to supply an existing element.
SelectState::item_with
查看源码pub fn item_with( row_id: impl Into<ElementId>, label: impl Into<Arc<str>>, state: SelectOptionState, row: Element, ) -> ElementDecorate one caller-owned option row, Base UI's `Select.Item`. `row_id` comes from [`Self::option_id_for_source`], so the row keeps the identity the popup's active-descendant relationship points at.
SelectState::item
查看源码pub fn item( row_id: impl Into<ElementId>, label: impl Into<Arc<str>>, state: SelectOptionState, ) -> ElementCreate the unstyled item part. Use [`Self::item_with`] to supply an existing element.
SelectState::item_text_with
查看源码pub fn item_text_with(text: Element) -> ElementDecorate one option's visible text, Base UI's `Select.ItemText`. The row already carries the accessible name, so the text is decoration.
SelectState::item_text
查看源码pub fn item_text() -> ElementCreate the unstyled item text part. Use [`Self::item_text_with`] to supply an existing element.
SelectState::item_indicator_with
查看源码pub fn item_indicator_with(indicator: Element) -> ElementDecorate one option's selected mark, Base UI's `Select.ItemIndicator`. The row already reports selection, so the indicator is hidden from assistive technology. Mount it only while the row is selected, exactly as Base UI does.
SelectState::item_indicator
查看源码pub fn item_indicator() -> ElementCreate the unstyled item indicator part. Use [`Self::item_indicator_with`] to supply an existing element.
SelectState::group_with
查看源码pub fn group_with(group: Element) -> ElementDecorate a caller-composed option group, Base UI's `Select.Group`.
SelectState::group
查看源码pub fn group() -> ElementCreate the unstyled group part. Use [`Self::group_with`] to supply an existing element.
SelectState::group_label_with
查看源码pub fn group_label_with(label_id: impl Into<ElementId>, label: Element) -> ElementDecorate a group's visible label, Base UI's `Select.GroupLabel`. Pass the same `label_id` to [`Element::accessibility_labelled_by`] on the group so the two are related without the text being copied.
SelectState::group_label
查看源码pub fn group_label(label_id: impl Into<ElementId>) -> ElementCreate the unstyled group label part. Use [`Self::group_label_with`] to supply an existing element.
SelectState::separator_with
查看源码pub fn separator_with(separator: Element) -> ElementDecorate a caller-owned divider between option groups, Base UI's `Select.Separator`.
SelectState::separator
查看源码pub fn separator() -> ElementCreate the unstyled separator part. Use [`Self::separator_with`] to supply an existing element.
SelectState::trigger_with
查看源码pub fn trigger_with( &self, id: impl Into<ElementId>, label: impl Into<Arc<str>>, trigger: Element, ) -> ElementDecorate an application-owned trigger without adding appearance, Base UI's `Select.Trigger`.
SelectState::trigger
查看源码pub fn trigger(&self, id: impl Into<ElementId>, label: impl Into<Arc<str>>) -> ElementCreate the unstyled trigger part. Use [`Self::trigger_with`] to supply an existing element.
SelectState::element
查看源码pub fn element<V, PopoverRoot, RenderOption, Change>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, label: impl Into<Arc<str>>, access: fn(&mut V) -> &mut SelectState<T>, trigger: Element, popover_root: PopoverRoot, render_option: RenderOption, change: Change, ) -> Element where V: 'static, T: Clone + 'static, PopoverRoot: Fn(SelectListState) -> Element + Clone + 'static, RenderOption: Fn(&PickerItem<T>, SelectOptionState) -> Element + Clone + 'static, Change: Fn(&mut V, T, &mut EventContext) + Clone + 'static,Build the complete unstyled select interaction from caller-owned trigger, popover, and rows. This is the `fn`-pointer entry point: a view that owns one select per field passes `Self::field`. A host that renders many declared selects through one view passes a per-instance [`StateAccessor`] to [`SelectState::element_with`] instead.
SelectState::element_with
查看源码pub fn element_with<V, PopoverRoot, RenderOption, Change>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, label: impl Into<Arc<str>>, access: StateAccessor<V, SelectState<T>>, trigger: Element, popover_root: PopoverRoot, render_option: RenderOption, change: Change, ) -> Element where V: 'static, T: Clone + 'static, PopoverRoot: Fn(SelectListState) -> Element + Clone + 'static, RenderOption: Fn(&PickerItem<T>, SelectOptionState) -> Element + Clone + 'static, Change: Fn(&mut V, T, &mut EventContext) + Clone + 'static,Build the select interaction against a per-instance retained-state accessor. Two selects declared by one view stay independent because the accessor, not the view type, decides which [`SelectState`] each registered listener resolves.
SelectState::element_with_trigger
查看源码pub fn element_with_trigger<V, PopoverRoot, RenderOption, Change>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, label: impl Into<Arc<str>>, access: fn(&mut V) -> &mut SelectState<T>, trigger: Element, popover_root: PopoverRoot, render_option: RenderOption, change: Change, ) -> Element where V: 'static, T: Clone + 'static, PopoverRoot: Fn(SelectListState, &SelectPopupParts<'_>) -> Element + Clone + 'static, RenderOption: Fn(&PickerItem<T>, SelectOptionState) -> Element + Clone + 'static, Change: Fn(&mut V, T, &mut EventContext) + Clone + 'static,Build the select interaction with access to the framework-owned popup parts. The surface renderer additionally receives [`SelectPopupParts`], whose `scroll_up_arrow_with` and `scroll_down_arrow_with` decorators carry Base UI's hovered scrolling behavior. Every other entry point is this one with a renderer that ignores them.
SelectState::element_with_trigger_accessor
查看源码pub fn element_with_trigger_accessor<V, PopoverRoot, RenderOption, Change>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, label: impl Into<Arc<str>>, access: StateAccessor<V, SelectState<T>>, trigger: Element, popover_root: PopoverRoot, render_option: RenderOption, change: Change, ) -> Element where V: 'static, T: Clone + 'static, PopoverRoot: Fn(SelectListState, &SelectPopupParts<'_>) -> Element + Clone + 'static, RenderOption: Fn(&PickerItem<T>, SelectOptionState) -> Element + Clone + 'static, Change: Fn(&mut V, T, &mut EventContext) + Clone + 'static,Build the popup-parts select interaction against a per-instance retained-state accessor.
