Expand description
General-purpose machinery for displaying Reflect
types using egui
Examples
Basic usage
use bevy_reflect::{Reflect, TypeRegistry};
use bevy_inspector_egui::egui_reflect_inspector::{InspectorUi, Context};
#[derive(Reflect)]
struct Data {
value: f32,
}
fn ui(data: &mut Data, ui: &mut egui::Ui, type_registry: &TypeRegistry) -> bool {
let mut cx = Context::default(); // empty context, with no access to the bevy world
let mut env = InspectorUi::new_no_short_circuit(type_registry, &mut cx); // no short circuiting, couldn't display `Handle<StandardMaterial>`
env.ui_for_reflect(data, ui)
}
Bevy specific usage
use bevy_reflect::{Reflect, TypeRegistry};
use bevy_inspector_egui::egui_reflect_inspector::{InspectorUi, Context};
use bevy_ecs::prelude::*;
use bevy_asset::Handle;
use bevy_pbr::StandardMaterial;
#[derive(Reflect)]
struct Data {
material: Handle<StandardMaterial>,
}
fn ui(mut data: Mut<Data>, ui: &mut egui::Ui, world: &mut World, type_registry: &TypeRegistry) {
let mut cx = Context {
world: Some(world.into()),
};
let mut env = InspectorUi::for_bevy(type_registry, &mut cx);
// alternatively
// use crate::bevy_inspector::short_circuit;
// let mut env = InspectorUi::new(type_registry, &mut cx, Some(short_circuit::short_circuit), Some(short_circuit::short_circuit_readonly));
let changed = env.ui_for_reflect(data.bypass_change_detection(), ui);
if changed {
data.set_changed();
}
}
Structs
Functions
Display the value without any
Context
or short circuiting behaviour.
This means that for example bevy’s Handle<StandardMaterial>
values cannot be displayed,
as they would need to have access to the World
.Type Definitions
Function which will be executed for every field recursively, which can be used to skip regular traversal.
This can be used to recognize
Handle<T>
types and display them as their actual value instead.