Components / overlay
CommandPalette view
A query field over a list of commands.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::overlay::CommandPalette;
Reviewed in command-palette.
Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
commands(commands: impl IntoIterator<Item = Command>) -> Self
Commands
Need a Context, so they need a view.
set_commands(commands: Vec<Command>, cx: &mut Context<Self>)
set_query(query: impl Into<SharedString>, cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
query(cx: &App) -> SharedString
query_input() -> &Entity<TextInput>
focus_query(window: &mut Window, cx: &mut App)
active_id(cx: &App) -> Option<SharedString>
Reports
The variants of the event it emits. It never applies the change itself.
- QueryChanged
- Invoked
- Dismissed
Example · command-palette
fn command_palette(window: &mut Window, cx: &mut App) -> AnyElement {
ensure_menus(window, cx);
let palette = cx.global::<SceneMenus>().palette.clone();
let theme = cx.theme().clone();
// A palette is summoned over whatever is on screen, so it sits centred
// near the top of the surface rather than in a corner of it.
stack(&theme)
.w_full()
.h(px(420.0))
.items_center()
.pt(px(theme.spacing.xxl))
.child(palette)
.into_any_element()
}