mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 08:18:49 -05:00
Add ListDrawerSettings
This commit is contained in:
parent
e730c49e40
commit
96025fbb61
@ -28,16 +28,23 @@ namespace TriInspector.Elements
|
||||
|
||||
public TriListElement(TriProperty property)
|
||||
{
|
||||
property.TryGetAttribute(out ListDrawerSettings settings);
|
||||
|
||||
_property = property;
|
||||
_reorderableListGui = new ReorderableList(null, _property.ArrayElementType)
|
||||
{
|
||||
draggable = false,
|
||||
displayAdd = true,
|
||||
displayRemove = true,
|
||||
draggable = settings?.Draggable ?? true,
|
||||
displayAdd = settings == null || !settings.HideAddButton,
|
||||
displayRemove = settings == null || !settings.HideRemoveButton,
|
||||
drawHeaderCallback = DrawHeaderCallback,
|
||||
elementHeightCallback = ElementHeightCallback,
|
||||
drawElementCallback = DrawElementCallback,
|
||||
};
|
||||
|
||||
if (!_reorderableListGui.displayAdd && !_reorderableListGui.displayRemove)
|
||||
{
|
||||
_reorderableListGui.footerHeight = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Update()
|
||||
@ -166,7 +173,8 @@ namespace TriInspector.Elements
|
||||
};
|
||||
|
||||
TriEditorGUI.Foldout(labelRect, _property);
|
||||
GUI.Label(arraySizeRect, $"{_reorderableListGui.count} items", Styles.ItemsCount);
|
||||
var label = _reorderableListGui.count == 0 ? "Empty" : $"{_reorderableListGui.count} items";
|
||||
GUI.Label(arraySizeRect, label, Styles.ItemsCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
14
Runtime/Attributes/ListDrawerSettings.cs
Normal file
14
Runtime/Attributes/ListDrawerSettings.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public sealed class ListDrawerSettings : Attribute
|
||||
{
|
||||
public bool Draggable { get; set; } = true;
|
||||
public bool HideAddButton { get; set; }
|
||||
public bool HideRemoveButton { get; set; }
|
||||
}
|
||||
}
|
3
Runtime/Attributes/ListDrawerSettings.cs.meta
Normal file
3
Runtime/Attributes/ListDrawerSettings.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d58dcfa9a4df4af09d44c31a6f74ab26
|
||||
timeCreated: 1642779136
|
Loading…
Reference in New Issue
Block a user