Skip to main content

Module multi_combobox

Module multi_combobox 

Source
Available on crate feature multi-combobox only.
Expand description

A searchable field that collects several values, each shown as a removable chip above the field.

It works like the combobox and shares its field, list and filtering, with these differences:

  • Choosing a suggestion adds it and keeps the list open, with the query cleared so the next name can be typed straight away.
  • Chosen suggestions stay in the list with a tick, in their usual place, so the list does not jump. Choosing a ticked suggestion removes it.
  • The chosen values sit above the field as chips, in the order they were chosen, and wrap onto new lines when the field is narrow. A chip’s x removes it, and so does Backspace in an empty field, starting with the last chip.

State holds the options, the query and the chosen values. The app owns it and passes every Event to State::update, which returns an Output when a value is added or removed.

use iced::Element;
use iced_cube::forms::multi_combobox::{self, Output, multi_combobox};

#[derive(Debug, Clone)]
enum Message {
    Guests(multi_combobox::Event),
}

struct App {
    guests: multi_combobox::State<&'static str>,
}

impl App {
    fn update(&mut self, message: Message) {
        let Message::Guests(event) = message;
        match self.guests.update(event) {
            Some(Output::Added(name)) => println!("Invited {name}"),
            Some(Output::Removed(name)) => println!("Uninvited {name}"),
            None => {}
        }
    }

    fn view(&self) -> Element<'_, Message> {
        multi_combobox(&self.guests)
            .placeholder("Add guests...")
            .on_event(Message::Guests)
            .into()
    }
}

Re-exports§

pub use crate::forms::combobox::VISIBLE_ROWS;

Structs§

MultiCombobox
A multi-select combobox builder. Convert it into an Element to render.
State
The options, the query, the highlight and the chosen values.

Enums§

Action
What a multi-select combobox keyboard shortcut does.
Event
Everything that changes a multi-select combobox.
Output
What an Event changed in the chosen values.

Functions§

chip_size
The chip size that suits a field size.
default_keymap
The default multi-select combobox shortcuts:
multi_combobox
Renders the chosen values as chips, the field under them and, while it is open, the suggestions of state.
remove_id
The widget id of the x on the chip for the option at index in State::options, in the multi-select combobox with MultiCombobox::id key.