Command
A command palette: a search field over grouped commands that narrows by fuzzy match, in place or as a dialog.
Inline
let palette = suggestions(ui.ctx()).width(380.0).show(ui);
if let Some(command) = palette.confirmed {
state.last = Some(command);
}
Dialog
let open_shortcut = KeyboardShortcut::new(Modifiers::COMMAND, Key::K);
if ui
.add(Button::new("Open Menu").style(&fastframe_ui::button_styles::Outline))
.clicked()
{
state.dialog_open = true;
}
ui.add(Kbd::shortcut(open_shortcut));
let palette = suggestions(ui.ctx()).placeholder("Type a command or search...");
if let Some(response) = CommandDialog::new(&mut state.dialog_open)
.shortcut(open_shortcut)
.show(ui.ctx(), palette)
&& let Some(command) = response.confirmed
{
state.last = Some(command);
}
Quick actions
let ctx = ui.ctx().clone();
let palette = Command::new("quick")
.items([
CommandItem::new("New File").icon(super::empty::glyph(&ctx, "plus")),
CommandItem::new("Duplicate").icon(super::empty::glyph(&ctx, "folder")),
CommandItem::new("Move to Trash").icon(super::empty::glyph(&ctx, "inbox")),
])
.searchable(false)
.width(380.0)
.show(ui);
if let Some(command) = palette.confirmed {
state.last = Some(command);
}
Scrollable
let groups = [
("Navigation", ["Home", "Inbox", "Documents", "Folders"]),
("Actions", ["New File", "Copy", "Rename", "Delete"]),
(
"Account",
["Profile", "Notifications", "Help & Support", "Sign Out"],
),
("Tools", ["Palette", "Terminal", "Globe", "Clock"]),
];
let mut palette = Command::new("scrollable").max_height(220.0).width(380.0);
for (index, (heading, commands)) in groups.into_iter().enumerate() {
if index > 0 {
palette = palette.separator();
}
palette =
palette.group(CommandGroup::new(heading).items(commands.map(CommandItem::new)));
}
if let Some(command) = palette.show(ui).confirmed {
state.last = Some(command);
}
The story above is gallery/src/stories/command.rs, running in your browser. Every snippet on this page is cut from it.