From 95f1956f48179662f0286173681ad460348123d7 Mon Sep 17 00:00:00 2001 From: Robert Wartenberg Date: Wed, 16 Aug 2023 14:47:35 +0200 Subject: [PATCH] fix: SetActive() takes care of btn. Add: ded. Hide funct --- .../Scripts/Controls/ComboBox/DropDownList.cs | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs index 40e90c4..2bbbf02 100644 --- a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs +++ b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs @@ -101,7 +101,7 @@ namespace UnityEngine.UI.Extensions [System.Serializable] public class ControlDisabledEvent : Events.UnityEvent { } - // fires when item is changed; + // fires when item changed between enabled and disabled; public ControlDisabledEvent OnControlDisabled; public void Start() @@ -427,38 +427,45 @@ namespace UnityEngine.UI.Extensions } /// - /// Toggle the drop down list + /// Toggle the drop down list if it's active /// - /// whether an item was directly clicked on + /// makes no difference, only for backwards compatibility reasons public void ToggleDropdownPanel(bool directClick) { - if (!isActive) return; + if (!isActive) + return; _overlayRT.transform.localScale = new Vector3(1, 1, 1); _scrollBarRT.transform.localScale = new Vector3(1, 1, 1); _isPanelActive = !_isPanelActive; _overlayRT.gameObject.SetActive(_isPanelActive); + if (_isPanelActive) - { transform.SetAsLastSibling(); - } - else if (directClick) - { - // scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y); - } + } + + /// + /// Hides the drop down panel if its visible at the moment + /// + public void HideDropDownPanel() + { + if (!_isPanelActive) + return; + ToggleDropdownPanel(false); } /// /// Updates the control and sets its active status, determines whether the dropdown will open ot not + /// and takes care of the underlying button to follow the status. /// /// public void SetActive(bool status) { - if (status != isActive) - { - OnControlDisabled?.Invoke(status); - } + if (status == isActive) + return; isActive = status; + OnControlDisabled?.Invoke(isActive); + _mainButton.btn.enabled = isActive; } } } \ No newline at end of file