diff --git a/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs b/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs
index 51ecb75..1350f87 100644
--- a/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs
+++ b/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs
@@ -95,8 +95,10 @@ namespace UnityEngine.UI.Extensions
}
}
- //TODO design as foldout for Inspector
- public Color ValidSelectionTextColor = Color.green;
+ 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;
@@ -226,11 +228,19 @@ namespace UnityEngine.UI.Extensions
///
private void RebuildPanel()
{
+ if (_isPanelActive) ToggleDropdownPanel();
+
//panel starts with all options
_panelItems.Clear();
_prunedPanelItems.Clear();
panelObjects.Clear();
+ //clear Autocomplete children in scene
+ foreach (Transform child in _itemsPanelRT.transform)
+ {
+ Destroy(child.gameObject);
+ }
+
foreach (string option in AvailableOptions)
{
_panelItems.Add(option.ToLower());
@@ -334,7 +344,7 @@ namespace UnityEngine.UI.Extensions
if (_panelItems.Count < 1) return;
- float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count);
+ float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) + DropdownOffset;
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
@@ -395,7 +405,7 @@ namespace UnityEngine.UI.Extensions
/// Toggle the drop down list
///
/// whether an item was directly clicked on
- public void ToggleDropdownPanel(bool directClick)
+ public void ToggleDropdownPanel(bool directClick = false)
{
_isPanelActive = !_isPanelActive;
diff --git a/Runtime/Scripts/Controls/ComboBox/ComboBox.cs b/Runtime/Scripts/Controls/ComboBox/ComboBox.cs
index 02da2ff..f0b7bbe 100644
--- a/Runtime/Scripts/Controls/ComboBox/ComboBox.cs
+++ b/Runtime/Scripts/Controls/ComboBox/ComboBox.cs
@@ -21,6 +21,9 @@ namespace UnityEngine.UI.Extensions
[SerializeField]
private int _itemsToDisplay;
+ [SerializeField]
+ private bool _sortItems = true;
+
[System.Serializable]
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent
{
@@ -178,7 +181,7 @@ namespace UnityEngine.UI.Extensions
{
_panelItems.Add(option.ToLower());
}
- _panelItems.Sort();
+ if(_sortItems) _panelItems.Sort();
List itemObjs = new List(panelObjects.Values);
panelObjects.Clear();