Skip to main content

Crate iced_palette

Crate iced_palette 

Source
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.
CommandBuilder
Builder for ergonomic command creation.
FuzzyMatch
Result of a fuzzy match.
Palette
A command palette widget.
PaletteConfig
Configuration for the command palette appearance.
PaletteState
State for the command palette.
PaletteStyle
Style configuration for the palette.
Shortcut
Keyboard shortcut for a command.

Enums§

CommandAction
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.