From cc22d39928887a19cfac48544895ed4d988f7366 Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Sun, 24 May 2026 18:04:04 +0300 Subject: [PATCH] fixed editing of `RefCell` --- fyrox-ui/src/inspector/editors/refcell.rs | 170 +++++++++------------- 1 file changed, 72 insertions(+), 98 deletions(-) diff --git a/fyrox-ui/src/inspector/editors/refcell.rs b/fyrox-ui/src/inspector/editors/refcell.rs index 93e6f529a..cfba224a4 100644 --- a/fyrox-ui/src/inspector/editors/refcell.rs +++ b/fyrox-ui/src/inspector/editors/refcell.rs @@ -19,17 +19,20 @@ // SOFTWARE. use crate::{ - core::reflect::prelude::*, + core::{pool::Handle, reflect::prelude::*, PhantomDataSendSync}, inspector::{ editors::{ PropertyEditorBuildContext, PropertyEditorDefinition, PropertyEditorInstance, PropertyEditorMessageContext, PropertyEditorTranslationContext, }, - InspectorError, PropertyChanged, + make_expander_container, FieldAction, Inspector, InspectorBuilder, InspectorContext, + InspectorContextArgs, InspectorError, InspectorMessage, PropertyChanged, }, - message::UiMessage, + message::{MessageDirection, UiMessage}, + widget::WidgetBuilder, + UiNode, }; -use fyrox_core::PhantomDataSendSync; +use fyrox_graph::SceneGraph; use std::{ any::TypeId, cell::RefCell, @@ -76,117 +79,88 @@ where &self, ctx: PropertyEditorBuildContext, ) -> Result { - if let Some(definition) = ctx - .definition_container - .definitions() - .get(&TypeId::of::()) - { - let property_info = ctx.property_info; + let value = ctx.property_info.cast_value::>()?; - let value = property_info.cast_value::>()?.borrow(); + let inspector_context = InspectorContext::from_object(InspectorContextArgs { + object: value, + ctx: ctx.build_context, + definition_container: ctx.definition_container.clone(), + environment: ctx.environment.clone(), + layer_index: ctx.layer_index + 1, + generate_property_string_values: ctx.generate_property_string_values, + filter: ctx.filter, + name_column_width: ctx.name_column_width, + hide_name_column: false, + base_path: ctx.base_path.clone(), + has_parent_object: ctx.has_parent_object, + }); - let proxy_property_info = FieldRef { - metadata: &FieldMetadata { - name: property_info.name, - display_name: property_info.display_name, - read_only: property_info.read_only, - immutable_collection: property_info.immutable_collection, - min_value: property_info.min_value, - max_value: property_info.max_value, - step: property_info.step, - precision: property_info.precision, - tag: property_info.tag, - doc: property_info.doc, - }, - value: &*value, - }; + let editor; + let container = make_expander_container( + ctx.layer_index, + ctx.property_info.display_name, + ctx.property_info.doc, + Handle::::NONE, + { + editor = InspectorBuilder::new(WidgetBuilder::new()) + .with_context(inspector_context) + .build(ctx.build_context) + .to_base(); + editor + }, + ctx.name_column_width, + ctx.hide_name_column, + ctx.build_context, + ); - definition - .property_editor - .create_instance(PropertyEditorBuildContext { - build_context: ctx.build_context, - property_info: &proxy_property_info, - environment: ctx.environment.clone(), - definition_container: ctx.definition_container.clone(), - layer_index: ctx.layer_index, - generate_property_string_values: ctx.generate_property_string_values, - filter: ctx.filter, - name_column_width: ctx.name_column_width, - hide_name_column: ctx.hide_name_column, - base_path: ctx.base_path.clone(), - has_parent_object: ctx.has_parent_object, - }) - } else { - Err(InspectorError::Custom("No editor!".to_string())) - } + Ok(PropertyEditorInstance::Custom { container, editor }) } + /// Instead of creating a message to update its widget, + /// call [InspectorContext::sync] to directly send whatever messages are necessary + /// and return None. fn create_message( &self, ctx: PropertyEditorMessageContext, ) -> Result, InspectorError> { - if let Some(definition) = ctx - .definition_container - .definitions() - .get(&TypeId::of::()) - { - let property_info = ctx.property_info; + let value = ctx.property_info.cast_value::>()?; - let value = ctx.property_info.cast_value::>()?.borrow(); + let mut error_group = Vec::new(); - let proxy_property_info = FieldRef { - metadata: &FieldMetadata { - name: property_info.name, - display_name: property_info.display_name, - read_only: property_info.read_only, - immutable_collection: property_info.immutable_collection, - min_value: property_info.min_value, - max_value: property_info.max_value, - step: property_info.step, - precision: property_info.precision, - tag: property_info.tag, - doc: property_info.doc, - }, - value: &*value, - }; - - return definition - .property_editor - .create_message(PropertyEditorMessageContext { - property_info: &proxy_property_info, - environment: ctx.environment.clone(), - definition_container: ctx.definition_container.clone(), - instance: ctx.instance, - layer_index: ctx.layer_index, - ui: ctx.ui, - generate_property_string_values: ctx.generate_property_string_values, - filter: ctx.filter, - name_column_width: ctx.name_column_width, - hide_name_column: ctx.hide_name_column, - base_path: ctx.base_path.clone(), - has_parent_object: ctx.has_parent_object, - }); + let inspector_context = ctx + .ui + .node(ctx.instance) + .cast::() + .expect("Must be Inspector!") + .context() + .clone(); + if let Err(e) = inspector_context.sync( + value, + ctx.ui, + ctx.layer_index + 1, + ctx.generate_property_string_values, + ctx.filter, + ctx.base_path.clone(), + ) { + error_group.extend(e) } - Err(InspectorError::Custom("No editor!".to_string())) + if error_group.is_empty() { + Ok(None) + } else { + Err(InspectorError::Group(error_group)) + } } fn translate_message(&self, ctx: PropertyEditorTranslationContext) -> Option { - // Try translate other messages using inner property editor. - if let Some(definition) = ctx - .definition_container - .definitions() - .get(&TypeId::of::()) + if let Some(InspectorMessage::PropertyChanged(msg)) = ctx.message.data::() { - return definition.property_editor.translate_message( - PropertyEditorTranslationContext { - environment: ctx.environment.clone(), - name: ctx.name, - - message: ctx.message, - definition_container: ctx.definition_container.clone(), - }, - ); + if ctx.message.direction() == MessageDirection::FromWidget { + return Some(PropertyChanged { + name: ctx.name.to_owned(), + action: FieldAction::InspectableAction(Box::new(msg.clone())), + }); + } } None