1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use std::{any::Any, borrow::Cow, collections::HashMap};
use bevy_reflect::{FromType, TypeData};
pub(crate) mod default_options;
pub mod std_options;
#[derive(Hash, PartialEq, Eq, Clone, Debug)]
pub enum Target {
Field(usize),
VariantField(Cow<'static, str>, usize),
}
pub use bevy_inspector_egui_derive::InspectorOptions;
#[derive(Default)]
pub struct InspectorOptions {
options: HashMap<Target, Box<dyn TypeData>>,
}
impl Clone for InspectorOptions {
fn clone(&self) -> Self {
Self {
options: self
.options
.iter()
.map(|(target, data)| (target.clone(), TypeData::clone_type_data(&**data)))
.collect(),
}
}
}
impl InspectorOptions {
pub fn new() -> Self {
Self::default()
}
pub fn insert<T: TypeData>(&mut self, target: Target, options: T) {
self.options.insert(target, Box::new(options));
}
pub fn insert_boxed(&mut self, target: Target, options: Box<dyn TypeData>) {
self.options.insert(target, options);
}
pub fn get(&self, target: Target) -> Option<&dyn Any> {
self.options.get(&target).map(|value| value.as_any())
}
}
#[derive(Clone)]
pub struct ReflectInspectorOptions(pub InspectorOptions);
impl<T> FromType<T> for ReflectInspectorOptions
where
InspectorOptions: FromType<T>,
{
fn from_type() -> Self {
ReflectInspectorOptions(InspectorOptions::from_type())
}
}
pub trait InspectorOptionsType {
type TypedOptions: Default;
type Options: From<Self::TypedOptions>;
}