pub struct ComboboxState { /* private fields */ }Expand description
An ordered collection with editable search and committed values.
Opening with the pointer or an arrow clears the draft to show all options. Typing filters suggestions without changing the committed value. Enter or a result click commits; Escape, Tab, blur, and outside presses restore the committed label. Only the native input participates in Tab traversal.
Single selection is the default. Multiple mode toggles results without closing the popup or clearing the draft; consumers render selected-value chips.
Implementations§
Source§impl ComboboxState
impl ComboboxState
pub fn new( items: impl IntoIterator<Item = SearchItem>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self
Sourcepub fn multiple(self, multiple: bool) -> Self
pub fn multiple(self, multiple: bool) -> Self
Allows several committed values. Configure before rendering the state. Disabling multiple mode with more than one selected value is an error.
Sourcepub fn input(&self) -> &Entity<InputState>
pub fn input(&self) -> &Entity<InputState>
The native query state, also available for application text styling.
pub fn focus_handle(&self) -> &FocusHandle
pub fn items<'a>(&'a self, cx: &'a App) -> &'a [SearchItem]
Sourcepub fn visible_indices<'a>(&'a self, cx: &'a App) -> &'a [usize]
pub fn visible_indices<'a>(&'a self, cx: &'a App) -> &'a [usize]
Original item indices in search order, including matching disabled items.
pub fn highlighted_index(&self, cx: &App) -> Option<usize>
pub fn selected_indices(&self) -> &[usize]
pub fn is_selected(&self, index: usize) -> bool
pub fn selected_values(&self, cx: &App) -> Vec<SharedString>
pub fn selected_items<'a>( &'a self, cx: &'a App, ) -> impl Iterator<Item = &'a SearchItem>
pub fn visible_groups(&self, cx: &App) -> Vec<SharedString>
pub fn visible_group_indices(&self, group: Option<&str>, cx: &App) -> Vec<usize>
pub fn is_open(&self) -> bool
pub fn is_disabled(&self) -> bool
Sourcepub fn set_selected_values<V: AsRef<str>>(
&mut self,
values: impl IntoIterator<Item = V>,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> bool
pub fn set_selected_values<V: AsRef<str>>( &mut self, values: impl IntoIterator<Item = V>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> bool
Sets committed values and closes the draft without emitting Change. Unknown/disabled values and multiple values in single mode are rejected.
Sourcepub fn set_items(
&mut self,
items: impl IntoIterator<Item = SearchItem>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_items( &mut self, items: impl IntoIterator<Item = SearchItem>, window: &mut Window, cx: &mut Context<'_, Self>, )
Replaces options without emitting Change. Selection follows stable values; missing or disabled values are removed. An active native draft and IME composition remain untouched. Closed single selection refreshes its label.
Sourcepub fn remove_value(
&mut self,
value: &str,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> bool
pub fn remove_value( &mut self, value: &str, window: &mut Window, cx: &mut Context<'_, Self>, ) -> bool
Removes a committed value as a user action, returning focus to the query. Disabled controls and active native composition reject the request.
Sourcepub fn clear(&mut self, window: &mut Window, cx: &mut Context<'_, Self>) -> bool
pub fn clear(&mut self, window: &mut Window, cx: &mut Context<'_, Self>) -> bool
Clears committed values and the query as a user action, preserving whether results are open. Application-owned clear buttons call this method.
Sourcepub fn set_query(
&mut self,
query: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_query( &mut self, query: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )
Starts a focused draft query without changing the committed selection.
pub fn set_disabled( &mut self, disabled: bool, window: &mut Window, cx: &mut Context<'_, Self>, )
Trait Implementations§
impl EventEmitter<ComboboxEvent> for ComboboxState
Auto Trait Implementations§
impl !RefUnwindSafe for ComboboxState
impl !Send for ComboboxState
impl !Sync for ComboboxState
impl !UnwindSafe for ComboboxState
impl Forget for ComboboxState
impl Freeze for ComboboxStatewhere
NonZero<u32>: Freeze,
*const (): Freeze,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: Freeze,
PhantomData<fn(CommandState) -> CommandState>: Freeze,
PhantomData<fn(InputBaseState<InputMode>) -> InputBaseState<InputMode>>: Freeze,
*const ArcInner<RwLock<RawRwLock, FocusMap>> is !null: Freeze,
PhantomData<ArcInner<RwLock<RawRwLock, FocusMap>>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<usize>: Freeze,
*const RcInner<()> is !null: Freeze,
PhantomData<RcInner<()>>: Freeze,
*const dyn FnOnce() is !null: Freeze,
PhantomData<dyn FnOnce()>: Freeze,
impl Move for ComboboxState
impl Unpin for ComboboxState
impl UnsafeUnpin for ComboboxStatewhere
NonZeroU32Inner: UnsafeUnpin,
*const (): UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: UnsafeUnpin,
PhantomData<fn(CommandState) -> CommandState>: UnsafeUnpin,
PhantomData<fn(InputBaseState<InputMode>) -> InputBaseState<InputMode>>: UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, FocusMap>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<RawRwLock, FocusMap>>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
*const RcInner<()> is !null: UnsafeUnpin,
PhantomData<RcInner<()>>: UnsafeUnpin,
*const dyn FnOnce() is !null: UnsafeUnpin,
PhantomData<dyn FnOnce()>: UnsafeUnpin,
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more