diff --git a/src/UI/CacheObject/ICacheObjectController.cs b/src/UI/CacheObject/ICacheObjectController.cs index d240df8..0e5126f 100644 --- a/src/UI/CacheObject/ICacheObjectController.cs +++ b/src/UI/CacheObject/ICacheObjectController.cs @@ -1,8 +1,10 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using UnityExplorer.UI.CacheObject; +using UnityExplorer.UI.CacheObject.Views; namespace UnityExplorer.UI.CacheObject { @@ -15,4 +17,36 @@ namespace UnityExplorer.UI.CacheObject bool CanWrite { get; } } + + public static class CacheObjectControllerHelper + { + // Helper so that this doesn't need to be copy+pasted between each implementation of the interface + + public static void SetCell(CacheObjectCell cell, int index, IList cachedEntries, Action onDataSetToCell) + { + if (index < 0 || index >= cachedEntries.Count) + { + if (cell.Occupant != null) + cell.Occupant.UnlinkFromView(); + + cell.Disable(); + return; + } + + var entry = (CacheObjectBase)cachedEntries[index]; + + if (entry.CellView != null && entry.CellView != cell) + entry.UnlinkFromView(); + + if (cell.Occupant != null && cell.Occupant != entry) + cell.Occupant.UnlinkFromView(); + + if (entry.CellView != cell) + entry.SetView(cell); + + entry.SetDataToCell(cell); + + onDataSetToCell?.Invoke(cell); + } + } } diff --git a/src/UI/IValues/InteractiveDictionary.cs b/src/UI/IValues/InteractiveDictionary.cs index 7cce385..f943128 100644 --- a/src/UI/IValues/InteractiveDictionary.cs +++ b/src/UI/IValues/InteractiveDictionary.cs @@ -155,6 +155,14 @@ namespace UnityExplorer.UI.IValues { try { + //key = key.TryCast(KeyType); + + if (!RefIDictionary.Contains(key)) + { + ExplorerCore.LogWarning("Unable to set key! Key may have been boxed to/from Il2Cpp Object."); + return; + } + RefIDictionary[key] = value; var entry = cachedEntries[keyIndex]; @@ -169,42 +177,23 @@ namespace UnityExplorer.UI.IValues // KVP entry scroll pool - public void OnCellBorrowed(CacheKeyValuePairCell cell) - { - - } + public void OnCellBorrowed(CacheKeyValuePairCell cell) { } public void SetCell(CacheKeyValuePairCell cell, int index) { - if (index < 0 || index >= cachedEntries.Count) - { - if (cell.Occupant != null) - cell.Occupant.UnlinkFromView(); - - cell.Disable(); - return; - } - - var entry = cachedEntries[index]; - - if (entry.CellView != null && entry.CellView != cell) - entry.UnlinkFromView(); - - if (cell.Occupant != null && cell.Occupant != entry) - cell.Occupant.UnlinkFromView(); - - if (entry.CellView != cell) - entry.SetView(cell); - - entry.SetDataToCell(cell); - - SetCellLayout(cell); + CacheObjectControllerHelper.SetCell(cell, index, cachedEntries, SetCellLayout); } + public int AdjustedWidth => (int)UIRect.rect.width - 80; + //public int AdjustedKeyWidth => HalfWidth - 50; + public override void SetLayout() { var minHeight = 5f; + KeyTitleLayout.minWidth = AdjustedWidth * 0.44f; + ValueTitleLayout.minWidth = AdjustedWidth * 0.55f; + foreach (var cell in DictScrollPool.CellPool) { SetCellLayout(cell); @@ -215,16 +204,18 @@ namespace UnityExplorer.UI.IValues this.scrollLayout.minHeight = Math.Min(InspectorPanel.CurrentPanelHeight - 400f, minHeight); } - private void SetCellLayout(CacheKeyValuePairCell cell) + private void SetCellLayout(CacheObjectCell objcell) { - cell.KeyGroupLayout.minWidth = cell.AdjustedKeyWidth; - cell.RightGroupLayout.minWidth = cell.HalfWidth; + var cell = objcell as CacheKeyValuePairCell; + cell.KeyGroupLayout.minWidth = cell.AdjustedWidth * 0.44f; + cell.RightGroupLayout.minWidth = cell.AdjustedWidth * 0.55f; if (cell.Occupant?.IValue != null) cell.Occupant.IValue.SetLayout(); } private LayoutElement scrollLayout; + private RectTransform UIRect; public override GameObject CreateContent(GameObject parent) { @@ -233,6 +224,8 @@ namespace UnityExplorer.UI.IValues UIFactory.SetLayoutElement(UIRoot, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 475); UIRoot.AddComponent().verticalFit = ContentSizeFitter.FitMode.PreferredSize; + UIRect = UIRoot.GetComponent(); + // Entries label TopLabel = UIFactory.CreateLabel(UIRoot, "EntryLabel", "not set", TextAnchor.MiddleLeft, fontSize: 16); @@ -242,14 +235,14 @@ namespace UnityExplorer.UI.IValues var titleGroup = UIFactory.CreateUIObject("TitleGroup", UIRoot); UIFactory.SetLayoutElement(titleGroup, minHeight: 25, flexibleWidth: 9999, flexibleHeight: 0); - UIFactory.SetLayoutGroup(titleGroup, true, true, true, true, padLeft: 50, padRight: 65); + UIFactory.SetLayoutGroup(titleGroup, false, true, true, true, padLeft: 65, padRight: 0, childAlignment: TextAnchor.LowerLeft); var keyTitle = UIFactory.CreateLabel(titleGroup, "KeyTitle", "Keys", TextAnchor.MiddleLeft); - //UIFactory.SetLayoutElement(keyTitle.gameObject, minWidth: ReflectionInspector.LeftGroupWidth); + UIFactory.SetLayoutElement(keyTitle.gameObject, minWidth: 100, flexibleWidth: 0); KeyTitleLayout = keyTitle.GetComponent(); var valueTitle = UIFactory.CreateLabel(titleGroup, "ValueTitle", "Values", TextAnchor.MiddleLeft); - //UIFactory.SetLayoutElement(valueTitle.gameObject, minWidth: ReflectionInspector.RightGroupWidth); + UIFactory.SetLayoutElement(valueTitle.gameObject, minWidth: 100, flexibleWidth: 0); ValueTitleLayout = valueTitle.GetComponent(); // entry scroll pool diff --git a/src/UI/IValues/InteractiveList.cs b/src/UI/IValues/InteractiveList.cs index ec43a66..b7c050e 100644 --- a/src/UI/IValues/InteractiveList.cs +++ b/src/UI/IValues/InteractiveList.cs @@ -142,6 +142,7 @@ namespace UnityExplorer.UI.IValues { try { + //value = value.TryCast(this.EntryType); RefIList[index] = value; var entry = cachedEntries[index]; @@ -173,27 +174,7 @@ namespace UnityExplorer.UI.IValues public void SetCell(CacheListEntryCell cell, int index) { - if (index < 0 || index >= cachedEntries.Count) - { - if (cell.Occupant != null) - cell.Occupant.UnlinkFromView(); - - cell.Disable(); - return; - } - - var entry = cachedEntries[index]; - - if (entry.CellView != null && entry.CellView != cell) - entry.UnlinkFromView(); - - if (cell.Occupant != null && cell.Occupant != entry) - cell.Occupant.UnlinkFromView(); - - if (entry.CellView != cell) - entry.SetView(cell); - - entry.SetDataToCell(cell); + CacheObjectControllerHelper.SetCell(cell, index, cachedEntries, null); } private LayoutElement scrollLayout; diff --git a/src/UI/Inspectors/ReflectionInspector.cs b/src/UI/Inspectors/ReflectionInspector.cs index 1bfabbb..a2ba9f7 100644 --- a/src/UI/Inspectors/ReflectionInspector.cs +++ b/src/UI/Inspectors/ReflectionInspector.cs @@ -256,29 +256,7 @@ namespace UnityExplorer.UI.Inspectors public void SetCell(CacheMemberCell cell, int index) { - if (index < 0 || index >= filteredMembers.Count) - { - if (cell.Occupant != null) - cell.Occupant.UnlinkFromView(); - - cell.Disable(); - return; - } - - var member = filteredMembers[index]; - - if (member.CellView != null && member.CellView != cell) - member.UnlinkFromView(); - - if (cell.Occupant != null && cell.Occupant != member) - cell.Occupant.UnlinkFromView(); - - if (member.CellView != cell) - member.SetView(cell); - - member.SetDataToCell(cell); - - SetCellLayout(cell); + CacheObjectControllerHelper.SetCell(cell, index, filteredMembers, SetCellLayout); } // Cell layout (fake table alignment)