Trait bevy_inspector_egui::Inspectable[][src]

pub trait Inspectable {
    type Attributes: Default + Clone;
    fn ui(
        &mut self,
        ui: &mut Ui,
        options: Self::Attributes,
        context: &Context<'_>
    ) -> bool; fn ui_raw(&mut self, ui: &mut Ui, options: Self::Attributes) { ... }
fn setup(app: &mut AppBuilder) { ... } }
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.

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: &Context) -> bool {
    println!("a = {}, b = {:?}", options.a, options.b);

// ...

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