pub trait Inspectable {
    type Attributes: Default + Clone;

    fn ui(
        &mut self,
        ui: &mut Ui,
        options: Self::Attributes,
        context: &mut Context<'_>
    ) -> bool; fn ui_raw(&mut self, ui: &mut Ui, options: Self::Attributes) { ... } fn setup(app: &mut App) { ... } }
Expand description

This trait describes how a struct should be displayed. It can be derived for structs and enums, see the crate-level docs for how to do that.

Default attributes

  • ignore: hides the field in the inspector
  • label: provides a label instead of using the field name
  • read_only: disables the UI
  • collapse: wraps the ui in an [egui::CollapsingHeader].
  • default: only for enums, specifies the default value when selecting a new variant
  • wrapper: wrap field UI in a custom function. Demo in the rust_types example.
  • override_where_clause: specifies which type bounds should be used for generics. For example #[inspectable(override_where_clause = "") struct Struct(PhantomData<M>) won’t include a M: Inspectable bound.

Required Associated Types§

The Attributes associated type specifies what attributes can be passed to a field. See the following snippet for an example:

struct MyCustomType;
struct MyWidgetAttributes { a: f32, b: Option<String> }

impl Inspectable for MyCustomType {
  type Attributes = MyWidgetAttributes;

  fn ui(&mut self, _: &mut egui::Ui, options: MyWidgetAttributes, context: &mut Context) -> bool {
    println!("a = {}, b = {:?}", options.a, options.b);
    false
  }
}

// ...

#[derive(Inspectable)]
struct InspectorData {
  #[inspectable(a = 10.0, b = None)]
  value: MyCustomType,
}

Required Methods§

This methods is responsible for building the egui ui. Returns whether any data was modified.

Provided Methods§

Displays the value without any context. Useful for usage outside of the plugins, where there is no access to the world or EguiContext.

Required setup for the bevy application, e.g. registering events. Note that this method will run for every instance of a type.

Implementations on Foreign Types§

Implementors§