From 6565b1a6d17c8114af79a12ddbb2bd1cba1bde8a Mon Sep 17 00:00:00 2001 From: "LARS-LAPTOP2\\larsme" Date: Mon, 27 Mar 2017 14:03:39 +0200 Subject: [PATCH] Option to change Input Text Color based on matching Items --- .../Controls/ComboBox/AutoCompleteComboBox.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs b/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs index d7fba23..9528a9c 100644 --- a/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs +++ b/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs @@ -114,6 +114,26 @@ namespace UnityEngine.UI.Extensions public bool SelectFirstItemOnStart = false; + [SerializeField] + private bool _ChangeInputTextColorBasedOnMatchingItems = false; + public bool ChangeInputTextColorBasedOnMatchingItems{ + get { return _remainInteractableIfEmpty; } + set + { + _ChangeInputTextColorBasedOnMatchingItems = value; + if (_ChangeInputTextColorBasedOnMatchingItems) { + SetInputTextColor (); + } + } + } + + //TODO design as foldout for Inspector + public Color ValidSelectionTextColor = Color.green; + public Color MatchingItemsRemainingTextColor = Color.black; + public Color NoItemsRemainingTextColor = Color.red; + + private bool _selectionIsValid = false; + public void Awake() { Initialize(); @@ -250,6 +270,7 @@ namespace UnityEngine.UI.Extensions } } interactible = _technicallyInteractible && (AvailableOptions.Count > 0 || _remainInteractableIfEmpty); + SetInputTextColor (); } /// @@ -348,8 +369,24 @@ namespace UnityEngine.UI.Extensions { ToggleDropdownPanel(false); } + _selectionIsValid = _panelItems.Contains (Text); + SetInputTextColor (); } + private void SetInputTextColor(){ + if (ChangeInputTextColorBasedOnMatchingItems) { + if (_selectionIsValid) { + _mainInput.textComponent.color = ValidSelectionTextColor; + } else if (_panelItems.Count > 0) { + _mainInput.textComponent.color = MatchingItemsRemainingTextColor; + } else { + _mainInput.textComponent.color = NoItemsRemainingTextColor; + } + } + } + + + /// /// Toggle the drop down list ///