canto/Assets/UI/Test/UserProfileItemVisualElement.cs
2025-08-06 12:51:11 -04:00

33 lines
966 B
C#

using UnityEngine.UIElements;
public class UserProfileItemVisualElement : VisualElement
{
// A reference to the UXML template. We will load this in the DataSource.
public static readonly string UxmlPath = "UserProfileItem";
// References to the UI elements inside the template.
private readonly Label nameLabel;
private readonly Label statusLabel;
public UserProfileItemVisualElement()
{
// This is where we find the child elements by their names from the UXML.
nameLabel = this.Q<Label>("user-name");
statusLabel = this.Q<Label>("user-status");
}
// Public method to bind the data.
public void SetData(UserProfile profile)
{
nameLabel.text = profile.Name;
statusLabel.text = profile.Status;
statusLabel.style.color = new StyleColor(profile.StatusColor);
}
// Public method to clear data for recycling.
public void ClearData()
{
nameLabel.text = string.Empty;
statusLabel.text = string.Empty;
}
}