Skip to main content

ComboBox

Struct ComboBox 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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: String

Live edit buffer — what the field currently displays.

§committed: String

Last confirmed value. Only changes via ComboBoxEvent::Committed — the host applies it the same way every other primitive’s events are applied.

§open: bool

Whether 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: bool

When true, every method below returns None — same “disabled means inert, not hidden” contract every other primitive’s disabled flag follows.

§focused: bool

Whether 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

Source

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.

Source

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.

Source

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).

Source

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).

Source

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 Clone for ComboBox

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ComboBox

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ComboBox

Source§

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

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ComboBox

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ComboBox

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ComboBox

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more