Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Support replacing the label text of each list element #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yuyu0127
Copy link
Contributor

@yuyu0127 yuyu0127 commented Mar 16, 2024

I added ElementLabelTextSelector property to ListViewSettings attribute, allowing for the editing of labels for each element in the list.
ElementLabelTextSelector property is the name of a method, which takes an int type element index as the argument and returns a string type label.

This works as follows:

image
using System.Collections.Generic;
using UnityEngine;
using Alchemy.Inspector;

namespace Alchemy.Samples
{
    public class LabelTextSample : MonoBehaviour
    {
        [LabelText("FOO LIST!"), ListViewSettings(ElementLabelTextSelector = nameof(GetFooLabel))]
        public List<float> fooList;
        [LabelText("BAR LIST!"), ListViewSettings(ElementLabelTextSelector = nameof(GetBarLabel))]
        public List<Vector3> barList;
        [LabelText("BAZ LIST!"), ListViewSettings(ElementLabelTextSelector = nameof(GetBazLabel))]
        public List<GameObject> bazList;

        private string GetFooLabel(int index) => $"FOO [{index}] {fooList[index]}";
        private string GetBarLabel(int index) => $"BAR [{index}] {barList[index]}";
        private string GetBazLabel(int index) => $"BAZ [{index}] {bazList[index]}";
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant