Make InputFieldRef helper, InteractiveString and IOUtility

This commit is contained in:
Sinai
2021-05-07 17:06:56 +10:00
parent 4931117b1e
commit d8f532d913
20 changed files with 405 additions and 206 deletions

View File

@ -76,11 +76,11 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
if (suggestions.Any() && CurrentHandler != null)
{
if (!CurrentHandler.InputField.gameObject.activeInHierarchy)
if (!CurrentHandler.InputField.UIRoot.activeInHierarchy)
ReleaseOwnership(CurrentHandler);
else
{
lastCaretPos = CurrentHandler.InputField.caretPosition;
lastCaretPos = CurrentHandler.InputField.InputField.caretPosition;
UpdatePosition();
}
}
@ -142,13 +142,13 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
private void UpdatePosition()
{
if (CurrentHandler == null || !CurrentHandler.InputField.isFocused)
if (CurrentHandler == null || !CurrentHandler.InputField.InputField.isFocused)
return;
Vector3 pos;
var input = CurrentHandler.InputField;
var textGen = input.textComponent.cachedTextGenerator;
var textGen = input.InputField.textComponent.cachedTextGenerator;
int caretPos = 0;
if (CurrentHandler.AnchorToCaretPosition)
{
@ -159,7 +159,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
}
pos = textGen.characters[caretPos].cursorPos;
pos = input.transform.TransformPoint(pos);
pos = input.UIRoot.transform.TransformPoint(pos);
uiRoot.transform.position = new Vector3(pos.x + 10, pos.y - 20, 0);

View File

@ -9,7 +9,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
{
public interface ISuggestionProvider
{
InputField InputField { get; }
InputFieldRef InputField { get; }
bool AnchorToCaretPosition { get; }
void OnSuggestionClicked(Suggestion suggestion);

View File

@ -21,20 +21,20 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
public Type BaseType { get; set; }
public Type[] GenericConstraints { get; set; }
public InputField InputField { get; }
public InputFieldRef InputField { get; }
public bool AnchorToCaretPosition => false;
private readonly List<Suggestion> suggestions = new List<Suggestion>();
private float timeOfLastCheck;
//private float timeOfLastCheck;
private HashSet<Type> allowedTypes;
public TypeCompleter(Type baseType, InputField inputField)
public TypeCompleter(Type baseType, InputFieldRef inputField)
{
BaseType = baseType;
InputField = inputField;
inputField.onValueChanged.AddListener(OnInputFieldChanged);
inputField.OnValueChanged += OnInputFieldChanged;
if (BaseType != null)
CacheTypes();
@ -47,9 +47,9 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
public void OnSuggestionClicked(Suggestion suggestion)
{
timeOfLastCheck = Time.realtimeSinceStartup;
//timeOfLastCheck = Time.realtimeSinceStartup;
InputField.text = suggestion.UnderlyingValue;
InputField.Text = suggestion.UnderlyingValue;
SuggestionClicked?.Invoke(suggestion);
suggestions.Clear();
@ -58,10 +58,10 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
private void OnInputFieldChanged(string value)
{
if (!timeOfLastCheck.OccuredEarlierThanDefault())
return;
timeOfLastCheck = Time.realtimeSinceStartup;
//if (!timeOfLastCheck.OccuredEarlierThanDefault())
// return;
//
//timeOfLastCheck = Time.realtimeSinceStartup;
value = value ?? "";

View File

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine.UI;
namespace UnityExplorer.UI.Widgets
{
// A simple helper class to handle a button's OnClick more effectively.
public class ButtonRef
{
public Action OnClick;
public Button Button { get; }
public Text ButtonText { get; }
public ButtonRef(Button button)
{
this.Button = button;
this.ButtonText = button.GetComponentInChildren<Text>();
button.onClick.AddListener(() => { OnClick?.Invoke(); });
}
}
}

View File

@ -19,28 +19,28 @@ namespace UnityExplorer.UI.Utility
{
get
{
if (InputField)
return InputField.gameObject;
if (InputField.UIRoot)
return InputField.UIRoot;
return null;
}
}
internal AutoSliderScrollbar Slider;
internal InputField InputField;
internal InputFieldRef InputField;
internal RectTransform ContentRect;
internal RectTransform ViewportRect;
internal static CanvasScaler RootScaler;
public InputFieldScroller(AutoSliderScrollbar sliderScroller, InputField inputField)
public InputFieldScroller(AutoSliderScrollbar sliderScroller, InputFieldRef inputField)
{
this.Slider = sliderScroller;
this.InputField = inputField;
inputField.onValueChanged.AddListener(OnTextChanged);
inputField.OnValueChanged += OnTextChanged;
ContentRect = inputField.GetComponent<RectTransform>();
ContentRect = inputField.UIRoot.GetComponent<RectTransform>();
ViewportRect = ContentRect.transform.parent.GetComponent<RectTransform>();
if (!RootScaler)
@ -88,22 +88,22 @@ namespace UnityExplorer.UI.Utility
internal void ProcessInputText()
{
var curInputRect = InputField.textComponent.rectTransform.rect;
var curInputRect = InputField.InputField.textComponent.rectTransform.rect;
var scaleFactor = RootScaler.scaleFactor;
// Current text settings
var texGenSettings = InputField.textComponent.GetGenerationSettings(curInputRect.size);
var texGenSettings = InputField.InputField.textComponent.GetGenerationSettings(curInputRect.size);
texGenSettings.generateOutOfBounds = false;
texGenSettings.scaleFactor = scaleFactor;
// Preferred text rect height
var textGen = InputField.textComponent.cachedTextGeneratorForLayout;
var textGen = InputField.InputField.textComponent.cachedTextGeneratorForLayout;
m_desiredContentHeight = textGen.GetPreferredHeight(m_lastText, texGenSettings) + 10;
// jump to bottom
if (InputField.caretPosition == InputField.text.Length
&& InputField.text.Length > 0
&& InputField.text[InputField.text.Length - 1] == '\n')
if (InputField.InputField.caretPosition == InputField.Text.Length
&& InputField.Text.Length > 0
&& InputField.Text[InputField.Text.Length - 1] == '\n')
{
m_wantJumpToBottom = true;
}