Dropdown button
A button with a menu of more options: whole, or split into a main action and a caret that stays live while the action is disabled.
Options
DropdownButton::new(Button::new("Options")).show(ui, |menu| {
menu.checkbox("Disabled", &mut state.disabled);
menu.checkbox("Main action disabled", &mut state.main_disabled);
menu.checkbox("Loading", &mut state.loading);
menu.checkbox("Compact", &mut state.compact);
});
Basic split
let mut export = Button::primary("Export").disabled(state.main_disabled);
if state.compact {
export = export.compact();
}
let shown = DropdownButton::split(export)
.disabled(state.disabled)
.menu(
Menu::new()
.placement(PopoverPlacement::BottomEnd)
.default_open(true),
)
.show(ui, |menu| {
if menu.item("Export all rows (.csv)").clicked() {
state.last_action = "Exported as CSV".to_owned();
}
if menu.item("Download report (.pdf)").clicked() {
state.last_action = "Exported as PDF".to_owned();
}
});
if shown.clicked() {
state.last_action = "Exported current view".to_owned();
}
Inner button options
let save = Button::new("Save")
.style(&fastframe_ui::button_styles::Outline)
.loading(state.loading)
.disabled(state.main_disabled);
let shown = DropdownButton::split(save)
.disabled(state.disabled)
.show(ui, |menu| {
if menu.item("Save as new file\u{2026}").clicked() {
state.last_action = "Saved as a new file".to_owned();
}
if menu.item("Save as template\u{2026}").clicked() {
state.last_action = "Saved as a template".to_owned();
}
});
if shown.clicked() {
state.last_action = "Saved document".to_owned();
}
Inherited styling
let shown = DropdownButton::split(Button::ghost("Open latest"))
.disabled(state.disabled)
.show(ui, |menu| {
for file in ["Quarterly Report.pdf", "Watchlist Layout.json"] {
if menu.item(file).clicked() {
state.last_action = format!("Opened {file}");
}
}
});
if shown.clicked() {
state.last_action = "Opened latest file".to_owned();
}
let shown = DropdownButton::split(Button::destructive("Danger")).show(ui, |menu| {
menu.item("Delete everything");
});
if shown.clicked() {
state.last_action = "Danger".to_owned();
}
The story above is gallery/src/stories/dropdown_button.rs, running in your browser. Every snippet on this page is cut from it.