mirror of
https://github.com/AnnulusGames/Alchemy.git
synced 2025-01-22 08:18:51 -05:00
Add: Support replacing the label text of each list element
This commit is contained in:
parent
bcaeef5ea9
commit
7409bf911c
@ -94,6 +94,9 @@ namespace Alchemy.Editor.Elements
|
||||
break;
|
||||
case PropertyField propertyField:
|
||||
propertyField.label = value;
|
||||
// To reflect changes, simply setting the value to the label property is not enough,
|
||||
// so you need to directly modify the label of elements with a specific class.
|
||||
propertyField.Query<Label>(className: "unity-property-field__label").ForEach(x => x.text = value);
|
||||
break;
|
||||
case SerializeReferenceField serializeReferenceField:
|
||||
serializeReferenceField.foldout.text = value;
|
||||
|
@ -25,16 +25,25 @@ namespace Alchemy.Editor.Elements
|
||||
{
|
||||
var arrayElement = property.GetArrayElementAtIndex(index);
|
||||
var e = new AlchemyPropertyField(arrayElement, property.GetPropertyType(true), true);
|
||||
var elementLabelTextSelector = property.GetAttribute<ListViewSettingsAttribute>()?.ElementLabelTextSelector;
|
||||
if (!string.IsNullOrEmpty(elementLabelTextSelector))
|
||||
{
|
||||
e.Label = (string)ReflectionHelper.Invoke(parentObj, elementLabelTextSelector, index);
|
||||
}
|
||||
element.Add(e);
|
||||
element.Bind(arrayElement.serializedObject);
|
||||
if (events != null)
|
||||
e.TrackPropertyValue(arrayElement, x =>
|
||||
{
|
||||
e.TrackPropertyValue(arrayElement, x =>
|
||||
if (events != null)
|
||||
{
|
||||
ReflectionHelper.Invoke(parentObj, events.OnItemChanged,
|
||||
new object[] { index, x.GetValue<object>() });
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(elementLabelTextSelector))
|
||||
{
|
||||
e.Label = (string)ReflectionHelper.Invoke(parentObj, elementLabelTextSelector, index);
|
||||
}
|
||||
});
|
||||
};
|
||||
listView.unbindItem = (element, index) =>
|
||||
{
|
||||
|
@ -216,6 +216,7 @@ namespace Alchemy.Inspector
|
||||
public SelectionType SelectionType { get; set; } = SelectionType.Multiple;
|
||||
public bool Reorderable { get; set; } = true;
|
||||
public ListViewReorderMode ReorderMode { get; set; } = ListViewReorderMode.Animated;
|
||||
public string ElementLabelTextSelector { get; set; } = null;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
|
Loading…
Reference in New Issue
Block a user