using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor.UIElements;
#endif
namespace AV.UITK
{
[Flags]
public enum Styles
{
None = 0,
/// Adds ".unity-button" class of .
Button = 2,
/// Adds ".tab" class, used by ".tabs-bar"
Tab = 4,
/// Adds ".blue" class - checked will appear blue.
Blue = 8,
/// Moves 's checkbox before label.
/// Adds ".toggle-left" class.
ToggleLeft = 16,
Separator = 32,
// TODO: FoldoutHeader style
ButtonBlue = Button | Blue,
TabBlue = Tab | Blue,
}
public static partial class FluentUITK
{
static MethodInfo setToolbarStyleSheet =
#if UNITY_EDITOR
typeof(Toolbar).GetMethod("SetToolbarStyleSheet", BindingFlags.NonPublic | BindingFlags.Static);
#else
null;
#endif
/// Setup pre-defined styles to VisualElement.
public static void DefineStyle(VisualElement x, Styles styles)
{
bool Has(Styles other) => (styles & other) != 0;
if (Has(Styles.Button))
x.AddToClassList("unity-button");
if (Has(Styles.Tab))
x.AddToClassList(TabClass);
if (Has(Styles.Blue))
x.AddToClassList("blue");
if (Has(Styles.Separator))
x.AddToClassList("separator");
if (Has(Styles.ToggleLeft))
{
x.AddToClassList("toggle-left");
if (x is Toggle)
x.Query(className: "unity-toggle__input").ForEach(e => x.Insert(0, e));
}
}
}
}