pub trait InspectorPrimitive: Reflect {
// Required methods
fn ui(
&mut self,
ui: &mut Ui,
options: &dyn Any,
id: Id,
env: InspectorUi<'_, '_>
) -> bool;
fn ui_readonly(
&self,
ui: &mut Ui,
options: &dyn Any,
id: Id,
env: InspectorUi<'_, '_>
);
}
Expand description
Custom UI implementation for a concrete type.
§Example Usage
use bevy::prelude::*;
use bevy_inspector_egui::inspector_egui_impls::{InspectorEguiImpl, InspectorPrimitive};
use bevy_inspector_egui::quick::ResourceInspectorPlugin;
use bevy_inspector_egui::reflect_inspector::InspectorUi;
#[derive(Reflect, Default)]
struct ToggleOption(bool);
impl InspectorPrimitive for ToggleOption {
fn ui(&mut self, ui: &mut egui::Ui, _: &dyn std::any::Any, _: egui::Id, _: InspectorUi<'_, '_>) -> bool {
let mut changed = ui.radio_value(&mut self.0, false, "Disabled").changed();
changed |= ui.radio_value(&mut self.0, true, "Enabled").changed();
changed
}
fn ui_readonly(&self, ui: &mut egui::Ui, _: &dyn std::any::Any, _: egui::Id, _: InspectorUi<'_, '_>) {
let mut copy = self.0;
ui.add_enabled_ui(false, |ui| {
ui.radio_value(&mut copy, false, "Disabled").changed();
ui.radio_value(&mut copy, true, "Enabled").changed();
});
}
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
// ...
.register_type_data::<ToggleOption, InspectorEguiImpl>()
.run();
}