Expand description
§iced_palette
A command palette library for Iced applications.
§Quick Start (Widget API)
ⓘ
use iced_palette::{Palette, PaletteState, Command, command};
// In your application state:
struct App {
palette: PaletteState,
}
// Define commands:
let commands = vec![
command("save", "Save File")
.description("Save the current file")
.action(Message::Save),
];
// In your view:
if self.palette.is_open() {
stack![
main_content,
Palette::new(&self.palette, &commands)
.on_query_change(Message::QueryChanged)
.on_select(|id| Message::CommandSelected(id))
.on_close(|| Message::PaletteClosed)
]
}§Helper Functions API (simpler, for external state management)
ⓘ
use iced_palette::{command_palette, Command, command};
// In your view, use the command_palette helper
if palette_is_open {
stack!(main_view, command_palette(...))
}Structs§
- Category
- Category for grouping commands.
- Command
- A command that can be executed from the palette.
- Command
Builder - Builder for ergonomic command creation.
- Fuzzy
Match - Result of a fuzzy match.
- Palette
- A command palette widget.
- Palette
Config - Configuration for the command palette appearance.
- Palette
State - State for the command palette.
- Palette
Style - Style configuration for the palette.
- Shortcut
- Keyboard shortcut for a command.
Enums§
- Command
Action - How a command produces its message.
Constants§
- INPUT_
ID - The widget ID for the command palette’s text input.
Use this with
focus_input()to focus the input when opening the palette.
Functions§
- collect_
shortcuts - Collects all shortcuts from commands, including those in submenus.
- command
- Creates a new command builder.
- command_
palette - Renders a command palette overlay with search input and default configuration.
- command_
palette_ styled - Renders a command palette overlay with search input and custom configuration.
- filter_
commands - Filters and sorts commands by fuzzy match score.
- find_
by_ shortcut - Finds a command that matches the given keyboard shortcut.
- find_
matching_ shortcut - Finds if a keyboard event matches any command shortcut. Returns the command ID if found.
- focus_
input - Returns a Task that focuses the command palette input. Call this from your update function when opening the palette.
- fuzzy_
match - Performs fuzzy matching with Sublime Text-style scoring.
- get_
filtered_ command_ index - Returns the filtered command indices for use with keyboard navigation. Call this to get the original command index when the user confirms selection.
- get_
filtered_ count - Returns the count of filtered commands for bounds checking.
- is_
toggle_ shortcut - Checks if a keyboard event matches the palette toggle shortcut (Ctrl+Space).
- navigate_
down - Calculates the next index when navigating down in a list with wrapping.
- navigate_
up - Calculates the next index when navigating up in a list with wrapping.
- palette_
focus - Returns a Task that focuses the palette input.