diff --git a/CHANGELOG.md b/CHANGELOG.md index 50127d73b0..555074d339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - Fixed an issue where authority changes returned by `ComponentUpdateSystem.GetAuthorityChangesReceived()` were returned in order from newest to oldest. [#1465](https://github.com/spatialos/gdk-for-unity/pull/1465) - Fixed a bug where the build system would throw a null reference exception if you don't have a configuration for a worker type. [#1461](https://github.com/spatialos/gdk-for-unity/pull/1461) - Fixed an incorrect callback registration for entity creation/removal in the `WorldCommandSender`. [#1473](https://github.com/spatialos/gdk-for-unity/pull/1462) +- Fixed the `TextField` indentation issue in the Worker Inspector due to nested `VisualElement` containers. [#1480](https://github.com/spatialos/gdk-for-unity/pull/1480) ## `0.3.10` - 2020-08-18 diff --git a/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/ComponentVisualElementGenerator.cs b/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/ComponentVisualElementGenerator.cs index f9cb02688c..c6da1d60f9 100644 --- a/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/ComponentVisualElementGenerator.cs +++ b/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/ComponentVisualElementGenerator.cs @@ -51,7 +51,7 @@ private void GenerateConstructor(TypeBlock typeBlock, UnityComponentDetails deta foreach (var field in details.FieldDetails) { - mb.TextList(typeGenerator.ToFieldInitialisation(field, "ComponentFoldout")); + mb.TextList(typeGenerator.ToFieldInitialisation(field, "ComponentFoldout", "0")); } mb.Line($"InjectComponentIcon(\"{GetComponentIcon(details)}\");"); diff --git a/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/FieldTypeHandler.cs b/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/FieldTypeHandler.cs index 84e186055f..1f4cc8f804 100644 --- a/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/FieldTypeHandler.cs +++ b/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/FieldTypeHandler.cs @@ -1,4 +1,5 @@ using System; +using System.Text; using System.Collections.Generic; using System.Linq; using Improbable.Gdk.CodeGeneration.Model; @@ -42,14 +43,14 @@ public string ToFieldDeclaration(UnityFieldDetails fieldDetails) } } - public IEnumerable ToFieldInitialisation(UnityFieldDetails fieldDetails, string parentContainer) + public IEnumerable ToFieldInitialisation(UnityFieldDetails fieldDetails, string parentContainer, string nestVar) { switch (fieldDetails.FieldType) { case SingularFieldType singularFieldType: var humanReadableName = Formatting.SnakeCaseToHumanReadable(fieldDetails.Name); - foreach (var initializer in GetFieldInitializer(singularFieldType.ContainedType, $"{fieldDetails.CamelCaseName}Field", humanReadableName, false)) + foreach (var initializer in GetFieldInitializer(singularFieldType.ContainedType, $"{fieldDetails.CamelCaseName}Field", humanReadableName, nestVar, false)) { yield return initializer; } @@ -59,7 +60,7 @@ public IEnumerable ToFieldInitialisation(UnityFieldDetails fieldDetails, case OptionFieldType optionFieldType: var innerUiType = GetUiFieldType(optionFieldType.ContainedType); - foreach (var initializer in GetFieldInitializer(optionFieldType.ContainedType, $"{fieldDetails.CamelCaseName}InnerField", "Value")) + foreach (var initializer in GetFieldInitializer(optionFieldType.ContainedType, $"{fieldDetails.CamelCaseName}InnerField", "Value", $"{nestVar} + 1")) { yield return initializer; } @@ -76,7 +77,7 @@ public IEnumerable ToFieldInitialisation(UnityFieldDetails fieldDetails, yield return $"{fieldDetails.CamelCaseName}Field = new PaginatedListView<{innerListType}, {listFieldType.ContainedType.FqnType}>(\"{Formatting.SnakeCaseToHumanReadable(fieldDetails.Name)}\", () => {{"; - foreach (var initializer in GetFieldInitializer(listFieldType.ContainedType, "inner", "")) + foreach (var initializer in GetFieldInitializer(listFieldType.ContainedType, "inner", "", $"{nestVar} + 1")) { yield return initializer; } @@ -98,7 +99,7 @@ public IEnumerable ToFieldInitialisation(UnityFieldDetails fieldDetails, $"{fieldDetails.CamelCaseName}Field = new PaginatedMapView<{innerKeyType}, {mapFieldType.KeyType.FqnType}, {innerValueType}, {mapFieldType.ValueType.FqnType}>(\"{Formatting.SnakeCaseToHumanReadable(fieldDetails.Name)}\","; yield return "() => {"; - foreach (var initializer in GetFieldInitializer(mapFieldType.KeyType, "inner", "Key")) + foreach (var initializer in GetFieldInitializer(mapFieldType.KeyType, "inner", "Key", $"{nestVar} + 1")) { yield return initializer; } @@ -107,7 +108,7 @@ public IEnumerable ToFieldInitialisation(UnityFieldDetails fieldDetails, yield return "() => {"; - foreach (var initializer in GetFieldInitializer(mapFieldType.ValueType, "inner", "Value")) + foreach (var initializer in GetFieldInitializer(mapFieldType.ValueType, "inner", "Value", $"{nestVar} + 1")) { yield return initializer; } @@ -136,22 +137,39 @@ public string ToUiFieldUpdate(UnityFieldDetails fieldDetails, string fieldParent } } - private IEnumerable GetFieldInitializer(ContainedType containedType, string uiElementName, string label, bool newVariable = true) + private string ConstructUiElement(ContainedType containedType, string uiElementName, string label, string nestVar, bool newVariable) { var inner = GetUiFieldType(containedType); - + var builder = new StringBuilder(); if (newVariable) { - yield return $"var {uiElementName} = new {inner}(\"{label}\");"; + builder.Append($"var {uiElementName} = "); } else { - yield return $"{uiElementName} = new {inner}(\"{label}\");"; + builder.Append($"{uiElementName} = "); + } + + if (containedType.Category == ValueType.Type) + { + builder.Append($"new {inner}(\"{label}\", {nestVar} + 1);"); } + else + { + builder.Append($"new {inner}(\"{label}\");"); + } + + return builder.ToString(); + } + + private IEnumerable GetFieldInitializer(ContainedType containedType, string uiElementName, string label, string nestVar, bool newVariable = true) + { + yield return ConstructUiElement(containedType, uiElementName, label, nestVar, newVariable); // These lines are part of the func to create an inner list item. if (containedType.Category != ValueType.Type) { + yield return $"{uiElementName}.labelElement.ShiftRightMargin({nestVar});"; yield return $"{uiElementName}.SetEnabled(false);"; } diff --git a/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/TypeVisualElementGenerator.cs b/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/TypeVisualElementGenerator.cs index 084825ad61..8d11bbb95e 100644 --- a/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/TypeVisualElementGenerator.cs +++ b/workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/TypeVisualElementGenerator.cs @@ -50,11 +50,11 @@ private TypeBlock GenerateType(UnityTypeDetails details) private void GenerateConstructor(TypeBlock typeBlock, UnityTypeDetails details) { - typeBlock.Method($"public {details.Name}Renderer(string label) : base(label)", mb => + typeBlock.Method($"public {details.Name}Renderer(string label, uint nest) : base(label)", mb => { foreach (var field in details.FieldDetails) { - mb.TextList(fieldTypeHandler.ToFieldInitialisation(field, "Container")); + mb.TextList(fieldTypeHandler.ToFieldInitialisation(field, "Container", "nest")); } }); } diff --git a/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/AssemblyInfo.cs b/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/AssemblyInfo.cs index d42e52dbea..da671bcaae 100644 --- a/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/AssemblyInfo.cs +++ b/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/AssemblyInfo.cs @@ -1,3 +1,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Improbable.Gdk.Debug.WorkerInspector.Codegen.EditmodeTests")] +[assembly: InternalsVisibleTo("Improbable.Gdk.Generated.Debug")] diff --git a/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/VisualElementExtensions.cs b/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/VisualElementExtensions.cs new file mode 100644 index 0000000000..e29b16ad7c --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/VisualElementExtensions.cs @@ -0,0 +1,14 @@ +using UnityEngine.UIElements; + +namespace Improbable.Gdk.Debug.WorkerInspector.Codegen +{ + internal static class VisualElementExtensions + { + public static void ShiftRightMargin(this VisualElement element, uint nest, float offset = -11) + { + var style = element.style; + var val = style.marginRight.value.value; + style.marginRight = new StyleLength(val + offset * nest); + } + } +} diff --git a/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/VisualElementExtensions.cs.meta b/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/VisualElementExtensions.cs.meta new file mode 100644 index 0000000000..73b9edcf3d --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/VisualElementExtensions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3748424ca0fa4491918357414d450b46 +timeCreated: 1599651271 \ No newline at end of file