mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
collect property paths in the inspector widget
This commit is contained in:
@@ -141,6 +141,7 @@ impl AssetInspector {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
});
|
||||
ui.send_message(InspectorMessage::context(
|
||||
self.inspector,
|
||||
@@ -183,6 +184,7 @@ impl AssetInspector {
|
||||
0,
|
||||
true,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
@@ -413,6 +413,7 @@ impl ExportWindow {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
});
|
||||
|
||||
inspector = InspectorBuilder::new(WidgetBuilder::new())
|
||||
@@ -663,9 +664,14 @@ impl ExportWindow {
|
||||
pub fn sync_to_model(&self, ui: &mut UserInterface) {
|
||||
if let Some(inspector) = ui.try_get_of_type::<Inspector>(self.inspector) {
|
||||
let ctx = inspector.context().clone();
|
||||
if let Err(sync_errors) =
|
||||
ctx.sync(&self.export_options, ui, 0, true, Default::default())
|
||||
{
|
||||
if let Err(sync_errors) = ctx.sync(
|
||||
&self.export_options,
|
||||
ui,
|
||||
0,
|
||||
true,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
) {
|
||||
for error in sync_errors {
|
||||
Log::err(format!("Failed to sync property. Reason: {error:?}"))
|
||||
}
|
||||
|
||||
@@ -650,6 +650,7 @@ impl BrushPanel {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
});
|
||||
|
||||
let inspector;
|
||||
@@ -677,7 +678,7 @@ impl BrushPanel {
|
||||
.context()
|
||||
.clone();
|
||||
|
||||
if let Err(e) = ctx.sync(brush, ui, 0, true, Default::default()) {
|
||||
if let Err(e) = ctx.sync(brush, ui, 0, true, Default::default(), Default::default()) {
|
||||
Log::writeln(
|
||||
MessageKind::Error,
|
||||
format!("Failed to sync BrushPanel's inspector. Reason: {e:?}"),
|
||||
|
||||
@@ -255,6 +255,7 @@ impl LightPanel {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
}))
|
||||
.build(ctx);
|
||||
inspector
|
||||
|
||||
@@ -105,6 +105,7 @@ impl ParameterPanel {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
@@ -132,7 +133,14 @@ impl ParameterPanel {
|
||||
.context()
|
||||
.clone();
|
||||
|
||||
if let Err(sync_errors) = ctx.sync(parameters, ui, 0, true, Default::default()) {
|
||||
if let Err(sync_errors) = ctx.sync(
|
||||
parameters,
|
||||
ui,
|
||||
0,
|
||||
true,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
) {
|
||||
for error in sync_errors {
|
||||
Log::err(format!("Failed to sync property. Reason: {error:?}"))
|
||||
}
|
||||
|
||||
@@ -257,6 +257,7 @@ impl ScriptPropertyEditorBuilder {
|
||||
generate_property_string_values,
|
||||
filter,
|
||||
name_column_width,
|
||||
base_path: Default::default(),
|
||||
})
|
||||
});
|
||||
|
||||
@@ -484,6 +485,7 @@ impl PropertyEditorDefinition for ScriptPropertyEditorDefinition {
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: Default::default(),
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
@@ -508,6 +510,7 @@ impl PropertyEditorDefinition for ScriptPropertyEditorDefinition {
|
||||
layer_index + 1,
|
||||
ctx.generate_property_string_values,
|
||||
ctx.filter,
|
||||
ctx.base_path.clone(),
|
||||
) {
|
||||
Err(InspectorError::Group(e))
|
||||
} else {
|
||||
|
||||
@@ -283,7 +283,7 @@ impl InspectorPlugin {
|
||||
.context()
|
||||
.clone();
|
||||
|
||||
ctx.sync(obj, ui, 0, true, Default::default())
|
||||
ctx.sync(obj, ui, 0, true, Default::default(), Default::default())
|
||||
}
|
||||
|
||||
fn change_context(
|
||||
@@ -312,6 +312,7 @@ impl InspectorPlugin {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
});
|
||||
|
||||
ui.send_message(InspectorMessage::context(
|
||||
|
||||
@@ -1064,6 +1064,7 @@ impl RagdollWizard {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
}))
|
||||
.build(ctx);
|
||||
inspector
|
||||
@@ -1219,7 +1220,14 @@ impl RagdollWizard {
|
||||
.context()
|
||||
.clone();
|
||||
|
||||
if let Err(sync_errors) = ctx.sync(&self.preset, ui, 0, true, Default::default()) {
|
||||
if let Err(sync_errors) = ctx.sync(
|
||||
&self.preset,
|
||||
ui,
|
||||
0,
|
||||
true,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
) {
|
||||
for error in sync_errors {
|
||||
Log::err(format!("Failed to sync property. Reason: {error:?}"))
|
||||
}
|
||||
|
||||
@@ -267,6 +267,7 @@ impl SettingsWindow {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
});
|
||||
let groups =
|
||||
context
|
||||
|
||||
@@ -161,6 +161,7 @@ impl SceneSettingsWindow {
|
||||
pass
|
||||
}),
|
||||
name_column_width: 150.0,
|
||||
base_path: Default::default(),
|
||||
});
|
||||
|
||||
ui.send_message(InspectorMessage::context(
|
||||
|
||||
@@ -127,6 +127,7 @@ fn create_items<'a, 'b, T, I>(
|
||||
generate_property_string_values: bool,
|
||||
filter: PropertyFilter,
|
||||
name_column_width: f32,
|
||||
base_path: String,
|
||||
) -> Result<Vec<Item>, InspectorError>
|
||||
where
|
||||
T: Reflect,
|
||||
@@ -171,6 +172,7 @@ where
|
||||
generate_property_string_values,
|
||||
filter: filter.clone(),
|
||||
name_column_width,
|
||||
base_path: format!("{base_path}[{index}]"),
|
||||
})?;
|
||||
|
||||
if let PropertyEditorInstance::Simple { editor } = editor {
|
||||
@@ -250,6 +252,7 @@ where
|
||||
property_info: &FieldRef<'a, '_>,
|
||||
sync_flag: u64,
|
||||
name_column_width: f32,
|
||||
base_path: String,
|
||||
) -> Result<Handle<UiNode>, InspectorError> {
|
||||
let definition_container = self
|
||||
.definition_container
|
||||
@@ -268,6 +271,7 @@ where
|
||||
self.generate_property_string_values,
|
||||
self.filter,
|
||||
name_column_width,
|
||||
base_path,
|
||||
)?
|
||||
} else {
|
||||
Vec::new()
|
||||
@@ -350,6 +354,7 @@ where
|
||||
ctx.property_info,
|
||||
ctx.sync_flag,
|
||||
ctx.name_column_width,
|
||||
ctx.base_path.clone(),
|
||||
)?;
|
||||
editor
|
||||
},
|
||||
@@ -375,6 +380,7 @@ where
|
||||
definition_container,
|
||||
environment,
|
||||
name_column_width,
|
||||
base_path,
|
||||
} = ctx;
|
||||
|
||||
let instance_ref = if let Some(instance) = ui.node(instance).cast::<ArrayEditor>() {
|
||||
@@ -431,6 +437,7 @@ where
|
||||
generate_property_string_values,
|
||||
filter: filter.clone(),
|
||||
name_column_width,
|
||||
base_path: format!("{base_path}[{index}]"),
|
||||
})?
|
||||
{
|
||||
ui.send_message(message.with_flags(ctx.sync_flag))
|
||||
|
||||
@@ -239,6 +239,7 @@ fn create_items<'a, 'b, T, I>(
|
||||
filter: PropertyFilter,
|
||||
immutable_collection: bool,
|
||||
name_column_width: f32,
|
||||
base_path: String,
|
||||
) -> Result<Vec<Item>, InspectorError>
|
||||
where
|
||||
T: CollectionItem,
|
||||
@@ -281,6 +282,7 @@ where
|
||||
generate_property_string_values,
|
||||
filter: filter.clone(),
|
||||
name_column_width,
|
||||
base_path: format!("{base_path}[{index}]"),
|
||||
})?;
|
||||
|
||||
if let PropertyEditorInstance::Simple { editor } = editor {
|
||||
@@ -386,6 +388,7 @@ where
|
||||
property_info: &FieldRef<'a, '_>,
|
||||
sync_flag: u64,
|
||||
name_column_width: f32,
|
||||
base_path: String,
|
||||
) -> Result<Handle<UiNode>, InspectorError> {
|
||||
let definition_container = self
|
||||
.definition_container
|
||||
@@ -405,6 +408,7 @@ where
|
||||
self.filter,
|
||||
self.immutable_collection,
|
||||
name_column_width,
|
||||
base_path,
|
||||
)?
|
||||
} else {
|
||||
Vec::new()
|
||||
@@ -510,6 +514,7 @@ where
|
||||
ctx.property_info,
|
||||
ctx.sync_flag,
|
||||
ctx.name_column_width,
|
||||
ctx.base_path.clone(),
|
||||
)?;
|
||||
editor
|
||||
},
|
||||
@@ -535,6 +540,7 @@ where
|
||||
generate_property_string_values,
|
||||
filter,
|
||||
name_column_width,
|
||||
base_path,
|
||||
} = ctx;
|
||||
|
||||
let instance_ref = if let Some(instance) = ui.node(instance).cast::<CollectionEditor<T>>() {
|
||||
@@ -561,6 +567,7 @@ where
|
||||
filter,
|
||||
property_info.immutable_collection,
|
||||
name_column_width,
|
||||
base_path,
|
||||
)?;
|
||||
|
||||
Ok(Some(CollectionEditorMessage::items(
|
||||
@@ -611,6 +618,7 @@ where
|
||||
generate_property_string_values,
|
||||
filter: filter.clone(),
|
||||
name_column_width,
|
||||
base_path: format!("{base_path}[{index}]"),
|
||||
})?
|
||||
{
|
||||
ui.send_message(message.with_flags(ctx.sync_flag))
|
||||
|
||||
@@ -107,6 +107,9 @@ pub struct EnumPropertyEditor<T: InspectableEnum> {
|
||||
#[visit(skip)]
|
||||
#[reflect(hidden)]
|
||||
pub name_column_width: f32,
|
||||
#[visit(skip)]
|
||||
#[reflect(hidden)]
|
||||
pub base_path: String,
|
||||
}
|
||||
|
||||
impl<T: InspectableEnum> Debug for EnumPropertyEditor<T> {
|
||||
@@ -129,6 +132,7 @@ impl<T: InspectableEnum> Clone for EnumPropertyEditor<T> {
|
||||
generate_property_string_values: self.generate_property_string_values,
|
||||
filter: self.filter.clone(),
|
||||
name_column_width: self.name_column_width,
|
||||
base_path: self.base_path.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,6 +185,7 @@ impl<T: InspectableEnum> Control for EnumPropertyEditor<T> {
|
||||
generate_property_string_values: self.generate_property_string_values,
|
||||
filter: self.filter.clone(),
|
||||
name_column_width: self.name_column_width,
|
||||
base_path: self.base_path.clone(),
|
||||
});
|
||||
|
||||
ui.send_message(InspectorMessage::context(
|
||||
@@ -296,6 +301,7 @@ impl EnumPropertyEditorBuilder {
|
||||
definition: &EnumPropertyEditorDefinition<T>,
|
||||
value: &T,
|
||||
name_column_width: f32,
|
||||
base_path: String,
|
||||
) -> Handle<UiNode> {
|
||||
let definition_container = self
|
||||
.definition_container
|
||||
@@ -311,6 +317,7 @@ impl EnumPropertyEditorBuilder {
|
||||
generate_property_string_values: self.generate_property_string_values,
|
||||
filter: self.filter.clone(),
|
||||
name_column_width,
|
||||
base_path: base_path.clone(),
|
||||
});
|
||||
|
||||
let inspector = InspectorBuilder::new(WidgetBuilder::new())
|
||||
@@ -333,6 +340,7 @@ impl EnumPropertyEditorBuilder {
|
||||
generate_property_string_values: self.generate_property_string_values,
|
||||
filter: self.filter,
|
||||
name_column_width,
|
||||
base_path,
|
||||
};
|
||||
|
||||
ctx.add_node(UiNode::new(editor))
|
||||
@@ -459,7 +467,13 @@ where
|
||||
.with_sync_flag(ctx.sync_flag)
|
||||
.with_generate_property_string_values(ctx.generate_property_string_values)
|
||||
.with_filter(ctx.filter)
|
||||
.build(ctx.build_context, self, value, ctx.name_column_width);
|
||||
.build(
|
||||
ctx.build_context,
|
||||
self,
|
||||
value,
|
||||
ctx.name_column_width,
|
||||
ctx.base_path.clone(),
|
||||
);
|
||||
editor
|
||||
},
|
||||
ctx.name_column_width,
|
||||
@@ -518,6 +532,7 @@ where
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: ctx.base_path.clone(),
|
||||
});
|
||||
|
||||
Ok(Some(InspectorMessage::context(
|
||||
@@ -541,6 +556,7 @@ where
|
||||
layer_index + 1,
|
||||
ctx.generate_property_string_values,
|
||||
ctx.filter,
|
||||
ctx.base_path.clone(),
|
||||
) {
|
||||
Err(InspectorError::Group(e))
|
||||
} else {
|
||||
|
||||
@@ -263,6 +263,7 @@ where
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: ctx.base_path.clone(),
|
||||
})?;
|
||||
|
||||
let wrapper = InheritablePropertyEditorBuilder::new(WidgetBuilder::new())
|
||||
@@ -353,6 +354,7 @@ where
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: ctx.base_path.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ where
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: ctx.base_path.clone(),
|
||||
});
|
||||
|
||||
let editor;
|
||||
@@ -144,6 +145,7 @@ where
|
||||
ctx.layer_index + 1,
|
||||
ctx.generate_property_string_values,
|
||||
ctx.filter,
|
||||
ctx.base_path.clone(),
|
||||
) {
|
||||
error_group.extend(e)
|
||||
}
|
||||
|
||||
@@ -179,6 +179,7 @@ pub struct PropertyEditorBuildContext<'a, 'b, 'c, 'd> {
|
||||
pub filter: PropertyFilter,
|
||||
/// Width of the property name column.
|
||||
pub name_column_width: f32,
|
||||
pub base_path: String,
|
||||
}
|
||||
|
||||
/// This structure is passed to [PropertyEditorDefinition::create_message] in order to generate a message that will
|
||||
@@ -218,6 +219,7 @@ pub struct PropertyEditorMessageContext<'a, 'b, 'c> {
|
||||
pub filter: PropertyFilter,
|
||||
/// Width of the property name column.
|
||||
pub name_column_width: f32,
|
||||
pub base_path: String,
|
||||
}
|
||||
|
||||
/// The details relevant to translating a message from an editor widget into
|
||||
|
||||
@@ -114,6 +114,7 @@ where
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: ctx.base_path.clone(),
|
||||
})
|
||||
} else {
|
||||
Err(InspectorError::Custom("No editor!".to_string()))
|
||||
@@ -163,6 +164,7 @@ where
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: ctx.base_path.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -255,6 +255,7 @@ where
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: ctx.base_path.clone(),
|
||||
})?;
|
||||
|
||||
let wrapper = StyledPropertyEditorBuilder::new(WidgetBuilder::new())
|
||||
@@ -332,6 +333,7 @@ where
|
||||
generate_property_string_values: ctx.generate_property_string_values,
|
||||
filter: ctx.filter,
|
||||
name_column_width: ctx.name_column_width,
|
||||
base_path: ctx.base_path.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -470,7 +470,8 @@ pub trait InspectorEnvironment: Any + Send + Sync {
|
||||
/// layer_index: 0,
|
||||
/// generate_property_string_values: true,
|
||||
/// filter: Default::default(),
|
||||
/// name_column_width: 150.0
|
||||
/// name_column_width: 150.0,
|
||||
/// base_path: Default::default(),
|
||||
/// });
|
||||
///
|
||||
/// InspectorBuilder::new(WidgetBuilder::new())
|
||||
@@ -556,6 +557,7 @@ pub struct ContextEntry {
|
||||
/// Storing the handle here allows us to which editor the user is indicating if the mouse is over the area
|
||||
/// surrounding the editor instead of the editor itself.
|
||||
pub property_container: Handle<UiNode>,
|
||||
pub property_path: String,
|
||||
}
|
||||
|
||||
impl PartialEq for ContextEntry {
|
||||
@@ -825,6 +827,7 @@ pub struct InspectorContextArgs<'a, 'b, 'c> {
|
||||
pub generate_property_string_values: bool,
|
||||
pub filter: PropertyFilter,
|
||||
pub name_column_width: f32,
|
||||
pub base_path: String,
|
||||
}
|
||||
|
||||
impl InspectorContext {
|
||||
@@ -855,6 +858,7 @@ impl InspectorContext {
|
||||
generate_property_string_values,
|
||||
filter,
|
||||
name_column_width,
|
||||
base_path,
|
||||
} = context;
|
||||
|
||||
let mut entries = Vec::new();
|
||||
@@ -882,6 +886,14 @@ impl InspectorContext {
|
||||
.definitions()
|
||||
.get(&info.value.type_id())
|
||||
{
|
||||
let property_path = if base_path.is_empty() {
|
||||
info.name.to_string()
|
||||
} else {
|
||||
format!("{}.{}", base_path, info.name)
|
||||
};
|
||||
|
||||
dbg!(&property_path);
|
||||
|
||||
let editor = match definition.property_editor.create_instance(
|
||||
PropertyEditorBuildContext {
|
||||
build_context: ctx,
|
||||
@@ -893,6 +905,7 @@ impl InspectorContext {
|
||||
generate_property_string_values,
|
||||
filter: filter.clone(),
|
||||
name_column_width,
|
||||
base_path: property_path.clone(),
|
||||
},
|
||||
) {
|
||||
Ok(instance) => {
|
||||
@@ -921,6 +934,7 @@ impl InspectorContext {
|
||||
property_tag: info.tag.to_string(),
|
||||
property_debug_output: field_text.clone(),
|
||||
property_container: container,
|
||||
property_path,
|
||||
});
|
||||
|
||||
if info.read_only {
|
||||
@@ -1030,6 +1044,7 @@ impl InspectorContext {
|
||||
layer_index: usize,
|
||||
generate_property_string_values: bool,
|
||||
filter: PropertyFilter,
|
||||
base_path: String,
|
||||
) -> Result<(), Vec<InspectorError>> {
|
||||
if object_type_id(object) != self.object_type_id {
|
||||
return Err(vec![InspectorError::OutOfSync]);
|
||||
@@ -1060,6 +1075,7 @@ impl InspectorContext {
|
||||
generate_property_string_values,
|
||||
filter: filter.clone(),
|
||||
name_column_width: self.name_column_width,
|
||||
base_path: base_path.clone(),
|
||||
};
|
||||
|
||||
match constructor.property_editor.create_message(ctx) {
|
||||
|
||||
@@ -233,6 +233,7 @@ impl SettingsWindow {
|
||||
generate_property_string_values: true,
|
||||
filter: Default::default(),
|
||||
name_column_width: 170.0,
|
||||
base_path: Default::default(),
|
||||
});
|
||||
let inspector = InspectorBuilder::new(WidgetBuilder::new())
|
||||
.with_context(context)
|
||||
@@ -288,7 +289,14 @@ impl SettingsWindow {
|
||||
.context()
|
||||
.clone();
|
||||
|
||||
Log::verify(ctx.sync(&**settings, ui, 0, true, Default::default()));
|
||||
Log::verify(ctx.sync(
|
||||
&**settings,
|
||||
ui,
|
||||
0,
|
||||
true,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user