pub struct ComboBox { /* private fields */ }
Expand description

A drop-down selection menu with a descriptive label.

egui::ComboBox::from_label("Select one!")
    .selected_text(format!("{:?}", selected))
    .show_ui(ui, |ui| {
        ui.selectable_value(&mut selected, Enum::First, "First");
        ui.selectable_value(&mut selected, Enum::Second, "Second");
        ui.selectable_value(&mut selected, Enum::Third, "Third");
    }
);

Implementations

Create new ComboBox with id and label

Label shown next to the combo box

Without label.

Set the width of the button and menu

What we show as the currently selected value

Use the provided function to render a different ComboBox icon. Defaults to a triangle that expands when the cursor is hovering over the ComboBox.

For example:

pub fn filled_triangle(
    ui: &egui::Ui,
    rect: egui::Rect,
    visuals: &egui::style::WidgetVisuals,
    _is_open: bool,
) {
    let rect = egui::Rect::from_center_size(
        rect.center(),
        egui::vec2(rect.width() * 0.6, rect.height() * 0.4),
    );
    ui.painter().add(egui::Shape::convex_polygon(
        vec![rect.left_top(), rect.right_top(), rect.center_bottom()],
        visuals.fg_stroke.color,
        visuals.fg_stroke,
    ));
}

egui::ComboBox::from_id_source("my-combobox")
    .selected_text(text)
    .icon(filled_triangle)
    .show_ui(ui, |_ui| {});

Show the combo box, with the given ui code for the menu contents.

Returns InnerResponse { inner: None } if the combo box is closed.

Show a list of items with the given selected index.

let alternatives = ["a", "b", "c", "d"];
let mut selected = 2;
egui::ComboBox::from_label("Select one!").show_index(
    ui,
    &mut selected,
    alternatives.len(),
    |i| alternatives[i].to_owned()
);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.