Skip to content

Commit

Permalink
use reflected type info
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Nov 6, 2024
1 parent 2ce6284 commit 645eb99
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
8 changes: 8 additions & 0 deletions crates/bevy-inspector-egui/src/inspector_egui_impls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Custom UI implementations for specific types. Check [`InspectorPrimitive`] for an example.
use crate::reflect_inspector::{errors::no_multiedit, InspectorUi, ProjectorReflect};
use bevy_log::info;
use bevy_reflect::{FromType, PartialReflect, Reflect, TypePath, TypeRegistry};
use bevy_utils::Instant;
use std::{
Expand Down Expand Up @@ -225,6 +226,13 @@ fn add_of_with_many<T: InspectorPrimitive>(
type_registry: &mut TypeRegistry,
fn_many: InspectorEguiImplFnMany,
) {
// Despite this running for f32 ; we then fail to retrieve it.
// TODO: check if their type id is similar, if not investigate why.
info!(
"registering InspectorEguiImpl for {} ({:?}",
std::any::type_name::<T>(),
TypeId::of::<T>()
);
type_registry
.get_mut(TypeId::of::<T>())
.unwrap_or_else(|| panic!("{} not registered", std::any::type_name::<T>()))
Expand Down
46 changes: 24 additions & 22 deletions crates/bevy-inspector-egui/src/reflect_inspector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,17 @@ impl InspectorUi<'_, '_> {
}
}

if let Some(s) = self
.type_registry
.get_type_data::<InspectorEguiImpl>(Any::type_id(value))
{
if let Some(value) = value.try_as_reflect_mut() {
return s.execute(value.as_any_mut(), ui, options, id, self.reborrow());
if let Some(reflected) = value.try_as_reflect_mut() {
if let Some(s) = self
.type_registry
.get_type_data::<InspectorEguiImpl>(reflected.reflect_type_info().type_id())
{
if let Some(value) = value.try_as_reflect_mut() {
return s.execute(value.as_any_mut(), ui, options, id, self.reborrow());
}
}
}

if let Some(changed) = (self.short_circuit)(self, value, ui, id, options) {
return changed;
}

match value.reflect_mut() {
ReflectMut::Struct(value) => self.ui_for_struct(value, ui, id, options),
ReflectMut::TupleStruct(value) => self.ui_for_tuple_struct(value, ui, id, options),
Expand Down Expand Up @@ -273,21 +271,25 @@ impl InspectorUi<'_, '_> {
) {
let mut options = options;
if options.is::<()>() {
if let Some(data) = self
.type_registry
.get_type_data::<ReflectInspectorOptions>(Any::type_id(value))
{
options = &data.0;
if let Some(value_reflect) = value.try_as_reflect() {
if let Some(data) = self
.type_registry
.get_type_data::<ReflectInspectorOptions>(value_reflect.type_id())
{
options = &data.0;
}
}
}

if let Some(s) = self
.type_registry
.get_type_data::<InspectorEguiImpl>(Any::type_id(value))
{
if let Some(value) = value.try_as_reflect() {
s.execute_readonly(value.as_any(), ui, options, id, self.reborrow());
return;
if let Some(value_reflect) = value.try_as_reflect() {
if let Some(s) = self
.type_registry
.get_type_data::<InspectorEguiImpl>(value_reflect.type_id())
{
if let Some(value) = value.try_as_reflect() {
s.execute_readonly(value.as_any(), ui, options, id, self.reborrow());
return;
}
}
}

Expand Down

0 comments on commit 645eb99

Please sign in to comment.