#[non_exhaustive]pub struct ComboBox {
pub id: WidgetId,
pub options: Vec<String>,
pub text: String,
pub committed: String,
pub open: bool,
pub highlighted: Option<usize>,
pub disabled: bool,
pub focused: bool,
}Expand description
Declarative description of an editable combo box: free text plus a filtered dropdown of fixed options.
§Examples
use quadraui::{ComboBox, ComboBoxEvent, Key, Modifiers, WidgetId};
let mut combo = ComboBox::new(
WidgetId::new("form:fruit"),
vec!["Apple".into(), "Apricot".into(), "Banana".into()],
);
combo.focused = true;
let event = combo.handle_key(&Key::Char('a'), &Modifiers::default());
assert_eq!(
event,
Some(ComboBoxEvent::TextChanged { id: combo.id.clone(), text: "a".into() })
);
combo.text = "ap".into();
assert_eq!(combo.filtered_indices(), vec![0, 1]);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: WidgetId§options: Vec<String>Fixed candidate list ComboBox::filtered_indices matches
against.
text: StringLive edit buffer — what the field currently displays.
committed: StringLast confirmed value. Only changes via
ComboBoxEvent::Committed — the host applies it the same way
every other primitive’s events are applied.
open: boolWhether the filtered dropdown is currently shown.
highlighted: Option<usize>Cursor index into the filtered list (from
ComboBox::filtered_indices), not the raw options list.
disabled: boolWhen true, every method below returns None — same
“disabled means inert, not hidden” contract every other
primitive’s disabled flag follows.
focused: boolWhether this field currently holds keyboard focus. Set by the
host’s focus-traversal logic; read by
ComboBox::handle_key to gate typed/arrow-key handling.
Implementations§
Source§impl ComboBox
impl ComboBox
Sourcepub fn new(id: WidgetId, options: Vec<String>) -> Self
pub fn new(id: WidgetId, options: Vec<String>) -> Self
A combo box over options, with an empty text buffer, closed
dropdown, enabled and unfocused. Set text/open/disabled/
focused directly afterwards (every field is pub) rather than
via a with_* chain — see docs/PRIMITIVE_RULES.md’s rule-8
history of why this crate stopped adding those.
Sourcepub fn filtered_indices(&self) -> Vec<usize>
pub fn filtered_indices(&self) -> Vec<usize>
Indices into ComboBox::options that case-insensitively
contain ComboBox::text as a substring. Empty text matches
every option.
Sourcepub fn layout<F>(
&self,
field_bounds: Rect,
viewport: Rect,
popup_width: f32,
max_popup_height: f32,
measure_item: F,
) -> ComboBoxLayout
pub fn layout<F>( &self, field_bounds: Rect, viewport: Rect, popup_width: f32, max_popup_height: f32, measure_item: F, ) -> ComboBoxLayout
Resolve the field’s own bounds plus, when open, the dropdown
popup’s layout — built by handing the filtered options to a
transient Completions value and delegating to its
placement algorithm (prefer below the field, flip above on
overflow, shift left on overflow, clip to viewport).
Sourcepub fn handle_key(
&self,
key: &Key,
_modifiers: &Modifiers,
) -> Option<ComboBoxEvent>
pub fn handle_key( &self, key: &Key, _modifiers: &Modifiers, ) -> Option<ComboBoxEvent>
Up/Down move the highlighted dropdown cursor; Enter
commits; Escape cancels an open edit; digits/letters and
Backspace edit text. Gated on focused and not disabled
— any other key is unhandled (None).
Sourcepub fn click(&self, hit: ComboBoxHit) -> Option<ComboBoxEvent>
pub fn click(&self, hit: ComboBoxHit) -> Option<ComboBoxEvent>
Pointer activation dispatcher: the host calls this after
resolving a MouseDown/MouseUp position through
ComboBoxLayout::hit_test. A hit on the field itself or
outside the control produces no event — focusing the field is
the host’s job, same as elsewhere in this crate.
Trait Implementations§
Source§impl Default for ComboBox
impl Default for ComboBox
Source§fn default() -> Self
fn default() -> Self
An empty combo box with no options. See ComboBox::new for one
with a real id/options list.
Source§impl<'de> Deserialize<'de> for ComboBox
impl<'de> Deserialize<'de> for ComboBox
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for ComboBox
Auto Trait Implementations§
impl Freeze for ComboBox
impl RefUnwindSafe for ComboBox
impl Send for ComboBox
impl Sync for ComboBox
impl Unpin for ComboBox
impl UnsafeUnpin for ComboBox
impl UnwindSafe for ComboBox
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSync for T
impl<T> DowncastSync for T
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