Trait gpui2::Action

source ·
pub trait Action: 'static {
    // Required methods
    fn boxed_clone(&self) -> Box<dyn Action>;
    fn as_any(&self) -> &dyn Any;
    fn partial_eq(&self, action: &dyn Action) -> bool;
    fn name(&self) -> &str;
    fn debug_name() -> &'static str
       where Self: Sized;
    fn build(value: Value) -> Result<Box<dyn Action>>
       where Self: Sized;
}
Expand description

Actions are used to implement keyboard-driven UI. When you declare an action, you can bind keys to the action in the keymap and listeners for that action in the element tree.

To declare a list of simple actions, you can use the actions! macro, which defines a simple unit struct action for each listed action name.

actions!(MoveUp, MoveDown, MoveLeft, MoveRight, Newline);

More complex data types can also be actions. If you annotate your type with the action derive macro it will be implemented and registered automatically.

#[derive(Clone, PartialEq, serde_derive::Deserialize, Action)]
pub struct SelectNext {
    pub replace_newest: bool,
}

If you want to control the behavior of the action trait manually, you can use the lower-level `#[register_action]`
macro, which only generates the code needed to register your action before `main`.

#[gpui::register_action] #[derive(gpui::serde::Deserialize, std::cmp::PartialEq, std::clone::Clone, std::fmt::Debug)] pub struct Paste { pub content: SharedString, }

impl gpui::Action for Paste { ///… }

Required Methods§

source

fn boxed_clone(&self) -> Box<dyn Action>

source

fn as_any(&self) -> &dyn Any

source

fn partial_eq(&self, action: &dyn Action) -> bool

source

fn name(&self) -> &str

source

fn debug_name() -> &'static strwhere Self: Sized,

source

fn build(value: Value) -> Result<Box<dyn Action>>where Self: Sized,

Implementations§

source§

impl dyn Action

source

pub fn type_id(&self) -> TypeId

Trait Implementations§

source§

impl Debug for dyn Action

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§