Reference
Element - Combo Box
Struct reference for iced::widget::ComboBox.
Element - Combo Box
Authoritative source: ref/doc/iced/widget/struct.ComboBox.html.
# Rustdoc summary
A widget for searching and selecting a single value from a list of options.
# Verified type declaration
rust
pub struct ComboBox<'a, T, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> where Theme: Catalog, Renderer: Renderer,{ /* private fields */ }
# When to use
Use this element struct when you need direct type-level control over a widget value.
# Why to use
It enables strongly typed composition and explicit builder method flows.
# Example References
- ref/examples/combo_box/src/main.rs
# Inline Examples (from rustdoc)
rust
use iced::widget::combo_box; struct State { fruits: combo_box::State<Fruit>, favorite: Option<Fruit>, } #[derive(Debug, Clone)] enum Fruit { Apple, Orange, Strawberry, Tomato, } #[derive(Debug, Clone)] enum Message { FruitSelected(Fruit), } fn view(state: &State) -> Element<'_, Message> { combo_box( &state.fruits, "Select your favorite fruit...", state.favorite.as_ref(), Message::FruitSelected ) .into() } fn update(state: &mut State, message: Message) { match message { Message::FruitSelected(fruit) => { state.favorite = Some(fruit); } } } impl std::fmt::Display for Fruit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { Self::Apple => "Apple", Self::Orange => "Orange", Self::Strawberry => "Strawberry", Self::Tomato => "Tomato", }) } }
# Related
# Use this when...
- You need the concrete widget struct type in signatures.
- You are debugging type errors involving generic bounds.
- You want lower-level control than constructor-only docs provide.
# Minimal example
rust
// Constructors usually produce this element type. // Name the type explicitly only when type-level APIs need it.
# How it works
Element structs are the underlying widget types used by constructors. Most app code can stay constructor-first, then use element docs for advanced typing/customization.
# Common patterns
rust
// Use constructors in normal UI code, // and reserve explicit element types for reusable abstractions.
# Gotchas / tips
- You usually do not need to construct element structs directly.
- Read trait bounds carefully when adding custom renderer/theme types.
- If a method is missing, check the related module page.