mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-12 23:06:56 +08:00
Add AllowNavigation property to ISuggestionProvider, implement
This commit is contained in:
@ -14,6 +14,8 @@ namespace UnityExplorer.UI.CSConsole
|
|||||||
|
|
||||||
public bool AnchorToCaretPosition => true;
|
public bool AnchorToCaretPosition => true;
|
||||||
|
|
||||||
|
bool ISuggestionProvider.AllowNavigation => true;
|
||||||
|
|
||||||
public void OnSuggestionClicked(Suggestion suggestion)
|
public void OnSuggestionClicked(Suggestion suggestion)
|
||||||
{
|
{
|
||||||
ConsoleController.InsertSuggestionAtCaret(suggestion.UnderlyingValue);
|
ConsoleController.InsertSuggestionAtCaret(suggestion.UnderlyingValue);
|
||||||
|
@ -33,6 +33,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
|
|
||||||
public static ButtonListSource<Suggestion> dataHandler;
|
public static ButtonListSource<Suggestion> dataHandler;
|
||||||
public static ScrollPool<ButtonCell> scrollPool;
|
public static ScrollPool<ButtonCell> scrollPool;
|
||||||
|
private static GameObject navigationTipRow;
|
||||||
|
|
||||||
private static List<Suggestion> Suggestions = new List<Suggestion>();
|
private static List<Suggestion> Suggestions = new List<Suggestion>();
|
||||||
private static int SelectedIndex = 0;
|
private static int SelectedIndex = 0;
|
||||||
@ -50,6 +51,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
public void TakeOwnership(ISuggestionProvider provider)
|
public void TakeOwnership(ISuggestionProvider provider)
|
||||||
{
|
{
|
||||||
CurrentHandler = provider;
|
CurrentHandler = provider;
|
||||||
|
navigationTipRow.SetActive(provider.AllowNavigation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReleaseOwnership(ISuggestionProvider provider)
|
public void ReleaseOwnership(ISuggestionProvider provider)
|
||||||
@ -199,20 +201,18 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
var suggestion = Suggestions[index];
|
var suggestion = Suggestions[index];
|
||||||
cell.Button.ButtonText.text = suggestion.DisplayText;
|
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())
|
if (cell.Rect.MinY() > scrollPool.Viewport.MinY())
|
||||||
{
|
diff = cell.Rect.MinY() - scrollPool.Viewport.MinY();
|
||||||
// cell is too far down
|
// if cell is too far up
|
||||||
var diff = cell.Rect.MinY() - scrollPool.Viewport.MinY();
|
|
||||||
var pos = scrollPool.Content.anchoredPosition;
|
|
||||||
pos.y -= diff;
|
|
||||||
scrollPool.Content.anchoredPosition = pos;
|
|
||||||
}
|
|
||||||
else if (cell.Rect.MaxY() < scrollPool.Viewport.MaxY())
|
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;
|
var pos = scrollPool.Content.anchoredPosition;
|
||||||
pos.y -= diff;
|
pos.y -= diff;
|
||||||
scrollPool.Content.anchoredPosition = pos;
|
scrollPool.Content.anchoredPosition = pos;
|
||||||
@ -312,9 +312,9 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999);
|
UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999);
|
||||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(scrollContent, true, false, true, false);
|
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(scrollContent, true, false, true, false);
|
||||||
|
|
||||||
var bottomRow = UIFactory.CreateHorizontalGroup(this.content, "BottomRow", true, true, true, true, 0, new Vector4(2, 2, 2, 2));
|
navigationTipRow = UIFactory.CreateHorizontalGroup(this.content, "BottomRow", true, true, true, true, 0, new Vector4(2, 2, 2, 2));
|
||||||
UIFactory.SetLayoutElement(bottomRow, minHeight: 20, flexibleWidth: 9999);
|
UIFactory.SetLayoutElement(navigationTipRow, minHeight: 20, flexibleWidth: 9999);
|
||||||
UIFactory.CreateLabel(bottomRow, "HelpText", "Control+Up/Down to select, Enter to use, Esc to hide",
|
UIFactory.CreateLabel(navigationTipRow, "HelpText", "Control+Up/Down to select, Enter to use",
|
||||||
TextAnchor.MiddleLeft, Color.grey, false, 13);
|
TextAnchor.MiddleLeft, Color.grey, false, 13);
|
||||||
|
|
||||||
UIRoot.SetActive(false);
|
UIRoot.SetActive(false);
|
||||||
|
@ -12,6 +12,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
InputFieldRef InputField { get; }
|
InputFieldRef InputField { get; }
|
||||||
bool AnchorToCaretPosition { get; }
|
bool AnchorToCaretPosition { get; }
|
||||||
|
|
||||||
|
bool AllowNavigation { get; }
|
||||||
|
|
||||||
void OnSuggestionClicked(Suggestion suggestion);
|
void OnSuggestionClicked(Suggestion suggestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Core.Input;
|
||||||
using UnityExplorer.Core.Runtime;
|
using UnityExplorer.Core.Runtime;
|
||||||
using UnityExplorer.UI.Models;
|
using UnityExplorer.UI.Models;
|
||||||
using UnityExplorer.UI.Panels;
|
using UnityExplorer.UI.Panels;
|
||||||
@ -31,6 +32,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
|
|
||||||
private string chosenSuggestion;
|
private string chosenSuggestion;
|
||||||
|
|
||||||
|
bool ISuggestionProvider.AllowNavigation => false;
|
||||||
|
|
||||||
public TypeCompleter(Type baseType, InputFieldRef inputField)
|
public TypeCompleter(Type baseType, InputFieldRef inputField)
|
||||||
{
|
{
|
||||||
BaseType = baseType;
|
BaseType = baseType;
|
||||||
|
Reference in New Issue
Block a user