Skip to main content

Module combobox

Module combobox 

Source
Available on crate feature combobox only.
Expand description

A text field with a list of suggestions that filters as you type.

State holds the options, the query, the highlighted suggestion and the selected value. The app owns it and passes every Event to State::update, which returns the value when one is chosen.

While the field has focus or the list is open, the combobox handles its own keys through a Keymap of Actions: arrows move the highlight, Enter chooses and Escape closes. See default_keymap. The list is drawn in the shared menu look on the anchored layer, so a click outside closes only the list, even inside a dialog or popover.

use iced::Element;
use iced_cube::forms::combobox::{self, combobox};

#[derive(Debug, Clone)]
enum Message {
    Fruit(combobox::Event),
}

struct App {
    fruit: combobox::State<&'static str>,
}

impl App {
    fn update(&mut self, message: Message) {
        let Message::Fruit(event) = message;
        if let Some(fruit) = self.fruit.update(event) {
            println!("Chose {fruit}");
        }
    }

    fn view(&self) -> Element<'_, Message> {
        combobox(&self.fruit)
            .placeholder("Search fruit...")
            .on_event(Message::Fruit)
            .into()
    }
}

Structs§

Combobox
A combobox builder. Convert it into an Element to render.
State
The options, the query and what is highlighted and selected.

Enums§

Action
What a combobox keyboard shortcut does.
Event
Everything that changes a combobox.

Constants§

DEFAULT_EMPTY
Shown when no option matches the query, unless the builder sets its own.
VISIBLE_ROWS
How many suggestions show at once unless the state sets its own number.

Functions§

combobox
Renders the field and, while it is open, the suggestions of state.
default_keymap
The default combobox shortcuts:
style
The field style: the input style, drawn focused while the list is open and with the destructive border while invalid.