// MIT License - Copyright (c) 2025 wallstop
// Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE
namespace WallstopStudios.UnityHelpers.Editor.CustomDrawers
{
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using WallstopStudios.UnityHelpers.Core.Attributes;
using WallstopStudios.UnityHelpers.Core.DataStructure.Adapters;
using WallstopStudios.UnityHelpers.Editor.CustomDrawers.Base;
using WallstopStudios.UnityHelpers.Editor.CustomDrawers.Utils;
using WallstopStudios.UnityHelpers.Editor.Settings;
using WallstopStudios.UnityHelpers.Utils;
///
/// UI Toolkit drawer for that provides search, pagination, and autocomplete.
///
[CustomPropertyDrawer(typeof(WValueDropDownAttribute))]
public sealed class WValueDropDownDrawer : PropertyDrawer
{
private sealed class PopupState
{
public string search = string.Empty;
public int page;
}
private sealed class DisplayLabelsCache
{
public object[] sourceOptions;
public string[] labels;
}
private const float ButtonWidth = DropDownShared.ButtonWidth;
private const float PageLabelWidth = DropDownShared.PageLabelWidth;
private const float PaginationButtonHeight = DropDownShared.PaginationButtonHeight;
private const float PopupWidth = DropDownShared.PopupWidth;
private const float OptionBottomPadding = DropDownShared.OptionBottomPadding;
private const float OptionRowExtraHeight = DropDownShared.OptionRowExtraHeight;
private const float EmptySearchHorizontalPadding =
DropDownShared.EmptySearchHorizontalPadding;
private const float EmptySearchExtraPadding = DropDownShared.EmptySearchExtraPadding;
private const string EmptyResultsMessage = DropDownShared.EmptyResultsMessage;
private static readonly GUIContent EmptyResultsContent = DropDownShared.EmptyResultsContent;
private static float s_cachedOptionControlHeight = -1f;
private static float s_cachedOptionRowHeight = -1f;
private static readonly Dictionary PopupStates = new();
private static readonly Dictionary DisplayLabelsCaches = new(
StringComparer.Ordinal
);
private static readonly Dictionary