41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using System.Linq;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace UVC.UIToolkit.Util
|
|
{
|
|
/// <summary>
|
|
/// UTKChildAnnotator는 VisualElement의 자식 요소들을 순회하며 첫 번째 자식에게 "first-child" 클래스를, 마지막 자식에게 "last-child" 클래스를 추가하는 유틸리티 클래스입니다.
|
|
/// </summary>
|
|
public static class UTKChildAnnotator
|
|
{
|
|
|
|
/// <summary>
|
|
/// 주어진 VisualElement의 자식 요소들을 순회하며 첫 번째 자식에게는 "first-child" 클래스를, 마지막 자식에게는 "last-child" 클래스를 추가합니다.
|
|
/// </summary>
|
|
/// <param name="parent">클래스를 추가할 VisualElement 부모 요소</param>
|
|
public static void AnnotateChild(VisualElement parent)
|
|
{
|
|
var children = parent.Children().ToList();
|
|
for (int i = 0; i < children.Count; i++)
|
|
{
|
|
var child = children[i];
|
|
if (i == 0)
|
|
{
|
|
child.RemoveFromClassList("first-child");
|
|
child.AddToClassList("first-child");
|
|
}
|
|
else if (i == children.Count - 1)
|
|
{
|
|
child.RemoveFromClassList("last-child");
|
|
child.AddToClassList("last-child");
|
|
}
|
|
else
|
|
{
|
|
child.RemoveFromClassList("first-child");
|
|
child.RemoveFromClassList("last-child");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
} |