mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 08:18:49 -05:00
Use value resolver for Title attribute
This commit is contained in:
parent
c11e6b70ef
commit
45328d5124
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user