mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Add TriPropertyOverrideContext for override child properties from parent darwer
This commit is contained in:
parent
f994a8aac7
commit
bdc4127e3c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -66,7 +66,10 @@ namespace TriInspector.Elements
|
||||
GUI.enabled &= _property.IsEnabled;
|
||||
EditorGUI.showMixedValue = _property.IsValueMixed;
|
||||
|
||||
base.OnGUI(position);
|
||||
using (TriPropertyOverrideContext.BeginProperty())
|
||||
{
|
||||
base.OnGUI(position);
|
||||
}
|
||||
|
||||
EditorGUI.showMixedValue = oldShowMixedValue;
|
||||
GUI.enabled = oldEnabled;
|
||||
|
@ -55,6 +55,11 @@ namespace TriInspector
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TriPropertyOverrideContext.Current != null)
|
||||
{
|
||||
return TriPropertyOverrideContext.Current.GetDisplayName(this);
|
||||
}
|
||||
|
||||
if (_displayNameBackingField == null)
|
||||
{
|
||||
if (TryGetAttribute(out HideLabelAttribute _))
|
||||
|
59
Editor/TriPropertyOverrideContext.cs
Normal file
59
Editor/TriPropertyOverrideContext.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Editor/TriPropertyOverrideContext.cs.meta
Normal file
3
Editor/TriPropertyOverrideContext.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 009410b38db449a1a47369c87a015b0d
|
||||
timeCreated: 1643555608
|
Loading…
Reference in New Issue
Block a user