Use value resolver for Title attribute

This commit is contained in:
VladV 2022-05-11 20:00:01 +03:00
parent c11e6b70ef
commit 45328d5124

View File

@ -1,5 +1,6 @@
using TriInspector;
using TriInspector.Drawers;
using TriInspector.Resolvers;
using UnityEditor;
using UnityEngine;
@ -14,6 +15,25 @@ namespace TriInspector.Drawers
private const int LineHeight = 2;
private const int SpaceBeforeContent = 3;
private ValueResolver<string> _titleResolver;
public override void Initialize(TriPropertyDefinition propertyDefinition)
{
base.Initialize(propertyDefinition);
_titleResolver = ValueResolver.ResolveString(propertyDefinition, Attribute.Title);
}
public override string CanDraw(TriProperty property)
{
if (_titleResolver.TryGetErrorString(out var error))
{
return error;
}
return base.CanDraw(property);
}
public override float GetHeight(float width, TriProperty property, TriElement next)
{
var extraHeight = SpaceBeforeTitle +
@ -44,7 +64,8 @@ namespace TriInspector.Drawers
yMin = lineRect.yMax + SpaceBeforeContent,
};
GUI.Label(titleRect, Attribute.Title, EditorStyles.boldLabel);
var title = _titleResolver.GetValue(property, "Error");
GUI.Label(titleRect, title, EditorStyles.boldLabel);
EditorGUI.DrawRect(lineRect, Color.gray);
next.OnGUI(contentRect);