diff --git a/src/UI/CSConsole/CSAutoCompleter.cs b/src/UI/CSConsole/CSAutoCompleter.cs index fa5f084..a638175 100644 --- a/src/UI/CSConsole/CSAutoCompleter.cs +++ b/src/UI/CSConsole/CSAutoCompleter.cs @@ -14,6 +14,8 @@ namespace UnityExplorer.UI.CSConsole public bool AnchorToCaretPosition => true; + bool ISuggestionProvider.AllowNavigation => true; + public void OnSuggestionClicked(Suggestion suggestion) { ConsoleController.InsertSuggestionAtCaret(suggestion.UnderlyingValue); diff --git a/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs b/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs index 011b2a3..884e9c1 100644 --- a/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs +++ b/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs @@ -33,6 +33,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete public static ButtonListSource dataHandler; public static ScrollPool scrollPool; + private static GameObject navigationTipRow; private static List Suggestions = new List(); private static int SelectedIndex = 0; @@ -50,6 +51,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete public void TakeOwnership(ISuggestionProvider provider) { CurrentHandler = provider; + navigationTipRow.SetActive(provider.AllowNavigation); } public void ReleaseOwnership(ISuggestionProvider provider) @@ -199,20 +201,18 @@ namespace UnityExplorer.UI.Widgets.AutoComplete var suggestion = Suggestions[index]; cell.Button.ButtonText.text = suggestion.DisplayText; - if (index == SelectedIndex && setFirstCell) + if (CurrentHandler.AllowNavigation && index == SelectedIndex && setFirstCell) { + float diff = 0f; + // if cell is too far down if (cell.Rect.MinY() > scrollPool.Viewport.MinY()) - { - // cell is too far down - var diff = cell.Rect.MinY() - scrollPool.Viewport.MinY(); - var pos = scrollPool.Content.anchoredPosition; - pos.y -= diff; - scrollPool.Content.anchoredPosition = pos; - } + diff = cell.Rect.MinY() - scrollPool.Viewport.MinY(); + // if cell is too far up else if (cell.Rect.MaxY() < scrollPool.Viewport.MaxY()) + diff = cell.Rect.MaxY() - scrollPool.Viewport.MaxY(); + + if (diff != 0.0f) { - // cell is too far up - var diff = cell.Rect.MaxY() - scrollPool.Viewport.MaxY(); var pos = scrollPool.Content.anchoredPosition; pos.y -= diff; scrollPool.Content.anchoredPosition = pos; @@ -312,9 +312,9 @@ namespace UnityExplorer.UI.Widgets.AutoComplete UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999); UIFactory.SetLayoutGroup(scrollContent, true, false, true, false); - var bottomRow = UIFactory.CreateHorizontalGroup(this.content, "BottomRow", true, true, true, true, 0, new Vector4(2, 2, 2, 2)); - UIFactory.SetLayoutElement(bottomRow, minHeight: 20, flexibleWidth: 9999); - UIFactory.CreateLabel(bottomRow, "HelpText", "Control+Up/Down to select, Enter to use, Esc to hide", + navigationTipRow = UIFactory.CreateHorizontalGroup(this.content, "BottomRow", true, true, true, true, 0, new Vector4(2, 2, 2, 2)); + UIFactory.SetLayoutElement(navigationTipRow, minHeight: 20, flexibleWidth: 9999); + UIFactory.CreateLabel(navigationTipRow, "HelpText", "Control+Up/Down to select, Enter to use", TextAnchor.MiddleLeft, Color.grey, false, 13); UIRoot.SetActive(false); diff --git a/src/UI/Widgets/AutoComplete/ISuggestionProvider.cs b/src/UI/Widgets/AutoComplete/ISuggestionProvider.cs index 6ff064b..648b776 100644 --- a/src/UI/Widgets/AutoComplete/ISuggestionProvider.cs +++ b/src/UI/Widgets/AutoComplete/ISuggestionProvider.cs @@ -12,6 +12,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete InputFieldRef InputField { get; } bool AnchorToCaretPosition { get; } + bool AllowNavigation { get; } + void OnSuggestionClicked(Suggestion suggestion); } } diff --git a/src/UI/Widgets/AutoComplete/TypeCompleter.cs b/src/UI/Widgets/AutoComplete/TypeCompleter.cs index 8700147..80a1a8f 100644 --- a/src/UI/Widgets/AutoComplete/TypeCompleter.cs +++ b/src/UI/Widgets/AutoComplete/TypeCompleter.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Text; using UnityEngine; using UnityEngine.UI; +using UnityExplorer.Core.Input; using UnityExplorer.Core.Runtime; using UnityExplorer.UI.Models; using UnityExplorer.UI.Panels; @@ -31,6 +32,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete private string chosenSuggestion; + bool ISuggestionProvider.AllowNavigation => false; + public TypeCompleter(Type baseType, InputFieldRef inputField) { BaseType = baseType;