Skip to main content

CommandPalette

Struct CommandPalette 

Source
pub struct CommandPalette<Msg> { /* private fields */ }
Expand description

A layer with a filter field over a list of commands, for running anything from the keyboard.

Typing filters the commands with fuzzy matching, best matches first, matched characters in the match colour. ↑/↓ (or Ctrl+P/Ctrl+N), PgUp/PgDn move the highlight, Enter runs the highlighted command. The mouse does the same: moving the pointer over a row moves the one highlight (a pointer resting where the palette opened waits until it moves), a click runs the clicked command and the wheel scrolls. It is dismissable by default: Esc, the close mark × at the top right and a click on the dimmed screen close it; dismissable(false) turns all three off. Running sends the close message first, then the command’s message. Only visible rows are drawn, so thousands of commands stay fast. Add it to the view while it should be shown; it opens as a modal layer in the upper part of the screen. Applications usually open it from the global palette action, bound to Ctrl+P.

With no options it lists the given commands. keymap adds the keymap’s actions with their keys; recent lists the given command ids first under “Recent” while nothing is typed; on_run reports which command ran, e.g. to remember recent ones.

Style keys: modal (with its pillar down the left edge), close-mark, layer-backdrop, layer-filter, layer-filter-mark, layer-filter-placeholder, layer-filter-cursor, layer-match, palette-item with hover (bg, fg, pillar), palette-chord, palette-header, layer-hint-key, layer-hint-label. Text: quvyta.palette.*, quvyta.layer.*.

Implementations§

Source§

impl<Msg: Clone + 'static> CommandPalette<Msg>

Source

pub fn new( commands: impl IntoIterator<Item = PaletteCommand<Msg>>, on_close: Msg, ) -> Self

A palette of commands; dismissing it (Esc, the close mark, a click outside) and running a command send on_close.

Source

pub fn keymap(self, include: bool) -> Self

Also lists the keymap’s actions (except moving focus and the palette itself), labelled from the language files and showing their first key. Running one runs the action as if its key had been pressed. Their ids are action:<name>.

Source

pub fn recent(self, ids: impl IntoIterator<Item = impl Into<String>>) -> Self

Ids of recently run commands, most recent first, listed on top while nothing is typed.

Source

pub fn placeholder(self, text: impl Into<String>) -> Self

The faint text of the empty filter; quvyta.palette.placeholder by default.

Source

pub fn width(self, cells: u16) -> Self

Width in cells, padding included; 72 by default. Narrow screens shrink it.

Source

pub fn dismissable(self, dismissable: bool) -> Self

Whether Esc, the close mark and a click on the dimmed screen close the palette; true by default. With false none of them works and the mark is not drawn; running a command still sends the close message.

Source

pub fn on_run(self, message: impl Fn(&str) -> Msg + 'static) -> Self

The message sent with the id of every command that runs, after the command’s own.

Trait Implementations§

Source§

impl<Msg: Clone + 'static> Widget<Msg> for CommandPalette<Msg>

Source§

fn measure(&self, _cx: &mut MeasureCx<'_>, _available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn paint_overlay(&self, cx: &mut PaintCx<'_>, _anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for CommandPalette<Msg>

§

impl<Msg> !Send for CommandPalette<Msg>

§

impl<Msg> !Sync for CommandPalette<Msg>

§

impl<Msg> !UnwindSafe for CommandPalette<Msg>

§

impl<Msg> Freeze for CommandPalette<Msg>
where Vec<PaletteCommand<Msg>>: Freeze, Msg: Freeze, Option<Box<dyn Fn(&str) -> Msg>>: Freeze,

§

impl<Msg> Unpin for CommandPalette<Msg>
where Vec<PaletteCommand<Msg>>: Unpin, Msg: Unpin, Option<Box<dyn Fn(&str) -> Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for CommandPalette<Msg>
where Vec<PaletteCommand<Msg>>: UnsafeUnpin, Msg: UnsafeUnpin, Option<Box<dyn Fn(&str) -> Msg>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.