Skip to content

Dropdown Menu

A menu below trigger, toggled by clicking it: the actions behind a "More" button. side and align place it elsewhere around the trigger.

ui.dropdown_menu

Basic

let more = ui.button("Options").outline().icon_end(IconName::ChevronDown);
let more = more.response();
ui.dropdown_menu(&more).children(|ui| {
ui.menu_label("My account");
ui.menu_item("Profile").icon(IconName::User);
ui.menu_item("Settings")
.icon(IconName::Settings)
.shortcut(Shortcut::command(','));
ui.menu_separator();
ui.menu_item("Sign out").danger();
});

Sections and descriptions

let more = ui
.button("More")
.icon(IconName::More)
.icon_only()
.ghost()
.tooltip("More actions")
.response();
ui.dropdown_menu(&more).children(|ui| {
ui.menu_label("Actions");
ui.menu_item("New file")
.icon(IconName::Plus)
.description("Create a new file")
.shortcut(Shortcut::command('n'));
ui.menu_item("Edit file")
.icon(IconName::Edit)
.description("Make changes")
.shortcut(Shortcut::command('e'));
ui.menu_separator();
ui.menu_label("Danger zone");
ui.menu_item("Delete file")
.icon(IconName::Trash)
.description("Move to trash")
.danger();
});

Several switched on at once

let view = ui.button("View").outline().icon_end(IconName::ChevronDown);
let view = view.response();
// A checked item leaves the menu open, so several can be changed in a row.
ui.dropdown_menu(&view).children(|ui| {
ui.menu_label("Show");
for (shown, name) in
self.menu_shown.iter_mut().zip(["Toolbar", "Sidebar", "Status bar"])
{
if ui.menu_item(name).checked(*shown).clicked() {
*shown = !*shown;
}
}
});

Disabled items

let edit = ui.button("Edit").outline().icon_end(IconName::ChevronDown);
let edit = edit.response();
ui.dropdown_menu(&edit).children(|ui| {
ui.menu_item("Undo").shortcut(Shortcut::command('z'));
ui.menu_item("Redo").shortcut(Shortcut::command('z').shift()).disabled(true);
ui.menu_separator();
ui.menu_item("Paste").shortcut(Shortcut::command('v')).disabled(true);
});

API reference

SettingDescription
.side(side: Side)The side of the trigger to appear on, below it by default. Without room there, it appears on the opposite side.
.align(align: Align)Where along that side: Align::Start lines it up with the start of the trigger, the default, Align::Center centers it on the trigger and Align::End lines up the ends.
.children(f: impl FnOnce(&mut Ui<'a>)Declares the items with f while open.