From fe97fa75996ecaf3c81b9d43d79c018df4ea8597 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 1 Jan 2023 16:52:08 +0000 Subject: [PATCH] Updated panel drawing for ComboBox controls and added DropdownOffset Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/393 --- .../Controls/ComboBox/AutoCompleteComboBox.cs | 198 ++++++++---------- Runtime/Scripts/Controls/ComboBox/ComboBox.cs | 85 +++----- .../Scripts/Controls/ComboBox/DropDownList.cs | 133 ++++++------ 3 files changed, 178 insertions(+), 238 deletions(-) diff --git a/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs b/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs index 853a444..acab967 100644 --- a/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs +++ b/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs @@ -13,7 +13,7 @@ namespace UnityEngine.UI.Extensions } [RequireComponent(typeof(RectTransform))] - [AddComponentMenu("UI/Extensions/AutoComplete ComboBox")] + [AddComponentMenu("UI/Extensions/ComboBox/AutoComplete ComboBox")] public class AutoCompleteComboBox : MonoBehaviour { public Color disabledTextColor; @@ -26,15 +26,12 @@ namespace UnityEngine.UI.Extensions /// public List AvailableOptions; - //private bool isInitialized = false; private bool _isPanelActive = false; private bool _hasDrawnOnce = false; private InputField _mainInput; private RectTransform _inputRT; - //private Button _arrow_Button; - private RectTransform _rectTransform; private RectTransform _overlayRT; @@ -52,11 +49,14 @@ namespace UnityEngine.UI.Extensions private List _prunedPanelItems; //items that used to show in the drop-down private Dictionary panelObjects; - + private GameObject itemTemplate; public string Text { get; private set; } + [SerializeField] + private float dropdownOffset; + [SerializeField] private float _scrollBarWidth = 20.0f; public float ScrollBarWidth @@ -69,9 +69,6 @@ namespace UnityEngine.UI.Extensions } } - // private int scrollOffset; //offset of the selected item - // private int _selectedIndex = 0; - [SerializeField] private int _itemsToDisplay; public int ItemsToDisplay @@ -84,28 +81,29 @@ namespace UnityEngine.UI.Extensions } } - public bool SelectFirstItemOnStart = false; + public bool SelectFirstItemOnStart = false; - [SerializeField] + [SerializeField] [Tooltip("Change input text color based on matching items")] private bool _ChangeInputTextColorBasedOnMatchingItems = false; - public bool InputColorMatching{ - get { return _ChangeInputTextColorBasedOnMatchingItems; } - set - { - _ChangeInputTextColorBasedOnMatchingItems = value; - if (_ChangeInputTextColorBasedOnMatchingItems) { - SetInputTextColor (); - } - } - } + public bool InputColorMatching + { + get { return _ChangeInputTextColorBasedOnMatchingItems; } + set + { + _ChangeInputTextColorBasedOnMatchingItems = value; + if (_ChangeInputTextColorBasedOnMatchingItems) + { + SetInputTextColor(); + } + } + } public float DropdownOffset = 10f; - //TODO design as foldout for Inspector public Color ValidSelectionTextColor = Color.green; - public Color MatchingItemsRemainingTextColor = Color.black; - public Color NoItemsRemainingTextColor = Color.red; + public Color MatchingItemsRemainingTextColor = Color.black; + public Color NoItemsRemainingTextColor = Color.red; public AutoCompleteSearchType autocompleteSearchType = AutoCompleteSearchType.Linq; @@ -114,36 +112,34 @@ namespace UnityEngine.UI.Extensions private bool _selectionIsValid = false; - [System.Serializable] - public class SelectionChangedEvent : UnityEngine.Events.UnityEvent { - } + [System.Serializable] + public class SelectionChangedEvent : Events.UnityEvent { } [System.Serializable] - public class SelectionTextChangedEvent : UnityEngine.Events.UnityEvent { - } + public class SelectionTextChangedEvent : Events.UnityEvent { } - [System.Serializable] - public class SelectionValidityChangedEvent : UnityEngine.Events.UnityEvent { - } + [System.Serializable] + public class SelectionValidityChangedEvent : Events.UnityEvent { } - // fires when input text is changed; - public SelectionTextChangedEvent OnSelectionTextChanged; - // fires when an Item gets selected / deselected (including when items are added/removed once this is possible) - public SelectionValidityChangedEvent OnSelectionValidityChanged; - // fires in both cases - public SelectionChangedEvent OnSelectionChanged; + // fires when input text is changed; + public SelectionTextChangedEvent OnSelectionTextChanged; + // fires when an Item gets selected / deselected (including when items are added/removed once this is possible) + public SelectionValidityChangedEvent OnSelectionValidityChanged; + // fires in both cases + public SelectionChangedEvent OnSelectionChanged; public void Awake() { Initialize(); } - public void Start() - { - if (SelectFirstItemOnStart && AvailableOptions.Count > 0) { - ToggleDropdownPanel (false); - OnItemClicked (AvailableOptions [0]); - } + public void Start() + { + if (SelectFirstItemOnStart && AvailableOptions.Count > 0) + { + ToggleDropdownPanel(false); + OnItemClicked(AvailableOptions[0]); + } RedrawPanel(); } @@ -156,8 +152,6 @@ namespace UnityEngine.UI.Extensions _inputRT = _rectTransform.Find("InputField").GetComponent(); _mainInput = _inputRT.GetComponent(); - //_arrow_Button = _rectTransform.FindChild ("ArrowBtn").GetComponent