Add TriPropertyOverrideContext for override child properties from parent darwer

This commit is contained in:
VladV 2022-01-30 18:44:16 +03:00
parent f994a8aac7
commit bdc4127e3c
5 changed files with 84 additions and 2 deletions

View File

@ -57,6 +57,7 @@ namespace TriInspector.Drawers
private readonly TriElement _cellElementContainer;
private readonly Dictionary<string, int> _cellIndexByName;
private readonly Dictionary<TriProperty, TriElement> _cellElements;
private readonly TableListPropertyOverrideContext _propertyOverrideContext;
public TableMultiColumnTreeView(TriProperty property, TriElement container)
: base(new TreeViewState(), BuildHeader(property))
@ -67,6 +68,8 @@ namespace TriInspector.Drawers
_cellIndexByName = new Dictionary<string, int>();
_cellElements = new Dictionary<TriProperty, TriElement>();
_propertyOverrideContext = new TableListPropertyOverrideContext();
rowHeight = 20;
showAlternatingRowBackgrounds = true;
showBorder = true;
@ -127,7 +130,8 @@ namespace TriInspector.Drawers
_cellElementContainer.AddChild(cellElement);
}
using (TriGuiHelper.PushLabelWidth(1f)) // todo fix this
using (TriPropertyOverrideContext.Override(_propertyOverrideContext))
//using (TriGuiHelper.PushLabelWidth(1f)) // todo fix this
{
_cellElements[cellValueProperty].OnGUI(cellRect);
}
@ -180,5 +184,13 @@ namespace TriInspector.Drawers
public TriProperty Property { get; }
}
private class TableListPropertyOverrideContext : TriPropertyOverrideContext
{
public override GUIContent GetDisplayName(TriProperty property)
{
return GUIContent.none;
}
}
}
}

View File

@ -66,7 +66,10 @@ namespace TriInspector.Elements
GUI.enabled &= _property.IsEnabled;
EditorGUI.showMixedValue = _property.IsValueMixed;
using (TriPropertyOverrideContext.BeginProperty())
{
base.OnGUI(position);
}
EditorGUI.showMixedValue = oldShowMixedValue;
GUI.enabled = oldEnabled;

View File

@ -55,6 +55,11 @@ namespace TriInspector
{
get
{
if (TriPropertyOverrideContext.Current != null)
{
return TriPropertyOverrideContext.Current.GetDisplayName(this);
}
if (_displayNameBackingField == null)
{
if (TryGetAttribute(out HideLabelAttribute _))

View File

@ -0,0 +1,59 @@
using System;
using UnityEngine;
namespace TriInspector
{
public abstract class TriPropertyOverrideContext
{
private static TriPropertyOverrideContext Override { get; set; }
public static TriPropertyOverrideContext Current { get; private set; }
public abstract GUIContent GetDisplayName(TriProperty property);
public static EnterPropertyScope BeginProperty()
{
return new EnterPropertyScope().Init();
}
public static OverrideScope BeginOverride(TriPropertyOverrideContext overrideContext)
{
return new OverrideScope(overrideContext);
}
public struct EnterPropertyScope : IDisposable
{
private TriPropertyOverrideContext _previousContext;
public EnterPropertyScope Init()
{
_previousContext = Current;
Current = Override;
return this;
}
public void Dispose()
{
Override = Current;
Current = _previousContext;
}
}
public readonly struct OverrideScope : IDisposable
{
public OverrideScope(TriPropertyOverrideContext context)
{
if (Override != null)
{
Debug.LogError($"TriPropertyContext already overriden with {Override.GetType()}");
}
Override = context;
}
public void Dispose()
{
Override = null;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 009410b38db449a1a47369c87a015b0d
timeCreated: 1643555608