mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 08:18:49 -05:00
31 lines
995 B
C#
31 lines
995 B
C#
using TriInspector;
|
|
using TriInspector.Drawers;
|
|
using TriInspector.Elements;
|
|
using TriInspector.Resolvers;
|
|
|
|
[assembly: RegisterTriAttributeDrawer(typeof(DropdownDrawer<>), TriDrawerOrder.Decorator)]
|
|
|
|
namespace TriInspector.Drawers
|
|
{
|
|
public class DropdownDrawer<T> : TriAttributeDrawer<DropdownAttribute>
|
|
{
|
|
private DropdownValuesResolver<T> _valuesResolver;
|
|
|
|
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
|
|
{
|
|
_valuesResolver = DropdownValuesResolver<T>.Resolve(propertyDefinition, Attribute.Values);
|
|
|
|
if (_valuesResolver.TryGetErrorString(out var error))
|
|
{
|
|
return error;
|
|
}
|
|
|
|
return TriExtensionInitializationResult.Ok;
|
|
}
|
|
|
|
public override TriElement CreateElement(TriProperty property, TriElement next)
|
|
{
|
|
return new TriDropdownElement(property, _valuesResolver.GetDropdownItems);
|
|
}
|
|
}
|
|
} |