|
|
|
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
namespace Unity.UIWidgets.service { |
|
|
|
public enum FloatingCursorDragState { |
|
|
|
Start, |
|
|
|
Update, |
|
|
|
|
|
|
|
End |
|
|
|
public enum SmartDashesType { |
|
|
|
disabled, |
|
|
|
enabled |
|
|
|
|
|
|
|
|
|
|
|
public class RawFloatingCursorPoint { |
|
|
|
public RawFloatingCursorPoint( |
|
|
|
Offset offset = null, |
|
|
|
FloatingCursorDragState? state = null |
|
|
|
) { |
|
|
|
D.assert(state != null); |
|
|
|
D.assert(state != FloatingCursorDragState.Update || offset != null); |
|
|
|
//D.assert(state == FloatingCursorDragState.Update ? offset != null : true);
|
|
|
|
this.offset = offset; |
|
|
|
this.state = state; |
|
|
|
} |
|
|
|
|
|
|
|
public readonly Offset offset; |
|
|
|
|
|
|
|
public readonly FloatingCursorDragState? state; |
|
|
|
public enum SmartQuotesType { |
|
|
|
disabled, |
|
|
|
enabled |
|
|
|
|
|
|
|
|
|
|
|
public class TextInputType : IEquatable<TextInputType> { |
|
|
|
public readonly int index; |
|
|
|
public readonly bool? signed; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public static readonly TextInputType text = new TextInputType(0); |
|
|
|
|
|
|
|
public static readonly TextInputType multiline = new TextInputType(1); |
|
|
|
|
|
|
|
public static readonly TextInputType number = numberWithOptions(); |
|
|
|
|
|
|
|
|
|
|
public static readonly TextInputType url = new TextInputType(6); |
|
|
|
|
|
|
|
public static readonly TextInputType visiblePassword = new TextInputType(7); |
|
|
|
|
|
|
|
public static readonly List<TextInputType> values = new List<TextInputType> { |
|
|
|
text, multiline, number, phone, datetime, emailAddress, url, visiblePassword |
|
|
|
}; |
|
|
|
|
|
|
|
"text", "multiline", "number", "phone", "datetime", "emailAddress", "url" |
|
|
|
"text", "multiline", "number", "phone", "datetime", "emailAddress", "url", "visiblePassword" |
|
|
|
}; |
|
|
|
|
|
|
|
public JSONNode toJson() { |
|
|
|
|
|
|
return $"{GetType().FullName}(name: {_name}, signed: {signed}, decimal: {decimalNum})"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public enum TextInputAction { |
|
|
|
none, |
|
|
|
unspecified, |
|
|
|
done, |
|
|
|
go, |
|
|
|
search, |
|
|
|
send, |
|
|
|
next, |
|
|
|
previous, |
|
|
|
continueAction, |
|
|
|
join, |
|
|
|
route, |
|
|
|
emergencyCall, |
|
|
|
newline |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public enum TextCapitalization { |
|
|
|
words, |
|
|
|
sentences, |
|
|
|
characters, |
|
|
|
none |
|
|
|
} |
|
|
|
public class TextInputConfiguration { |
|
|
|
public TextInputConfiguration( |
|
|
|
TextInputType inputType = null, |
|
|
|
bool obscureText = false, |
|
|
|
bool autocorrect = true, |
|
|
|
SmartDashesType? smartDashesType = null, |
|
|
|
SmartQuotesType? smartQuotesType = null, |
|
|
|
bool enableSuggestions = true, |
|
|
|
string actionLabel = null, |
|
|
|
TextInputAction inputAction = TextInputAction.done, |
|
|
|
ui.Brightness keyboardAppearance = ui.Brightness.light, |
|
|
|
TextCapitalization textCapitalization = TextCapitalization.none, |
|
|
|
bool unityTouchKeyboard = false |
|
|
|
) { |
|
|
|
D.assert(inputType != null); |
|
|
|
this.smartDashesType = |
|
|
|
smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled); |
|
|
|
this.smartQuotesType = |
|
|
|
smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled); |
|
|
|
this.inputType = inputType ?? TextInputType.text; |
|
|
|
this.obscureText = obscureText; |
|
|
|
this.autocorrect = autocorrect; |
|
|
|
this.enableSuggestions = enableSuggestions; |
|
|
|
this.actionLabel = actionLabel; |
|
|
|
this.inputAction = inputAction; |
|
|
|
this.textCapitalization = textCapitalization; |
|
|
|
this.keyboardAppearance = keyboardAppearance; |
|
|
|
this.unityTouchKeyboard = unityTouchKeyboard; |
|
|
|
} |
|
|
|
|
|
|
|
public readonly TextInputType inputType; |
|
|
|
public readonly bool obscureText; |
|
|
|
public readonly bool autocorrect; |
|
|
|
public readonly SmartDashesType smartDashesType; |
|
|
|
public readonly SmartQuotesType smartQuotesType; |
|
|
|
public readonly bool enableSuggestions; |
|
|
|
public readonly string actionLabel; |
|
|
|
public readonly TextInputAction inputAction; |
|
|
|
public readonly TextCapitalization textCapitalization; |
|
|
|
public readonly ui.Brightness keyboardAppearance; |
|
|
|
|
|
|
|
public readonly bool unityTouchKeyboard; |
|
|
|
|
|
|
|
public JSONNode toJson() { |
|
|
|
var json = new JSONObject(); |
|
|
|
json["inputType"] = inputType.toJson(); |
|
|
|
json["obscureText"] = obscureText; |
|
|
|
json["autocorrect"] = autocorrect; |
|
|
|
json["smartDashesType"] = smartDashesType.ToString(); |
|
|
|
json["smartQuotesType"] = smartQuotesType.ToString(); |
|
|
|
json["enableSuggestions"] = enableSuggestions; |
|
|
|
json["actionLabel"] = actionLabel; |
|
|
|
json["inputAction"] = inputAction.ToString(); |
|
|
|
json["unityTouchKeyboard"] = unityTouchKeyboard; |
|
|
|
json["textCapitalization"] = textCapitalization.ToString(); |
|
|
|
json["keyboardAppearance"] = keyboardAppearance.ToString(); |
|
|
|
return json; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static partial class TextInputUtils { |
|
|
|
internal static TextAffinity? _toTextAffinity(string affinity) { |
|
|
|
switch (affinity) { |
|
|
|
|
|
|
return TextInputAction.newline; |
|
|
|
} |
|
|
|
|
|
|
|
throw new UIWidgetsError("Unknown text input action: $action"); |
|
|
|
throw new UIWidgetsError($"Unknown text input action: {action}"); |
|
|
|
} |
|
|
|
|
|
|
|
public static FloatingCursorDragState _toTextCursorAction(string state) { |
|
|
|
|
|
|
return FloatingCursorDragState.End; |
|
|
|
} |
|
|
|
|
|
|
|
throw new UIWidgetsError("Unknown text cursor action: $state"); |
|
|
|
throw new UIWidgetsError(new List<DiagnosticsNode>() {new ErrorSummary($"Unknown text cursor action: {state}")}); |
|
|
|
} |
|
|
|
|
|
|
|
public static RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public enum FloatingCursorDragState { |
|
|
|
Start, |
|
|
|
Update, |
|
|
|
End |
|
|
|
} |
|
|
|
|
|
|
|
public class RawFloatingCursorPoint { |
|
|
|
public RawFloatingCursorPoint( |
|
|
|
Offset offset = null, |
|
|
|
FloatingCursorDragState? state = null |
|
|
|
) { |
|
|
|
D.assert(state != null); |
|
|
|
D.assert(state != FloatingCursorDragState.Update || offset != null); |
|
|
|
this.offset = offset; |
|
|
|
this.state = state; |
|
|
|
} |
|
|
|
|
|
|
|
public readonly Offset offset; |
|
|
|
|
|
|
|
public readonly FloatingCursorDragState? state; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public readonly string text; |
|
|
|
public readonly TextSelection selection; |
|
|
|
public readonly TextRange composing; |
|
|
|
static JSONNode defaultBoolNode = new JSONBool(false); |
|
|
|
|
|
|
|
public TextEditingValue( |
|
|
|
string text = "", |
|
|
|
|
|
|
D.assert(text != null); |
|
|
|
D.assert(selection != null); |
|
|
|
D.assert(composing != null); |
|
|
|
this.text = text; |
|
|
|
this.composing = composing ?? TextRange.empty; |
|
|
|
|
|
|
|
|
|
|
this.selection = selection.copyWith(start, end); |
|
|
|
} |
|
|
|
else { |
|
|
|
this.selection = TextSelection.collapsed(-1); |
|
|
|
this.selection = selection ?? TextSelection.collapsed(-1); |
|
|
|
public static TextEditingValue fromJSON(JSONObject json) { |
|
|
|
public static TextEditingValue fromJSON(JSONNode json) { |
|
|
|
TextAffinity? affinity = |
|
|
|
TextInputUtils._toTextAffinity(json["selectionAffinity"].Value); |
|
|
|
return new TextEditingValue( |
|
|
|
|
|
|
extentOffset: json.GetValueOrDefault("selectionExtent", defaultIndexNode).AsInt, |
|
|
|
affinity: affinity != null ? affinity.Value : TextAffinity.downstream, |
|
|
|
isDirectional: json["selectionIsDirectional"].AsBool |
|
|
|
isDirectional: json.GetValueOrDefault("selectionIsDirectional", defaultBoolNode).AsBool |
|
|
|
), |
|
|
|
composing: new TextRange( |
|
|
|
start: json.GetValueOrDefault("composingBase", defaultIndexNode).AsInt, |
|
|
|
|
|
|
json["composingExtent"] = composing.end; |
|
|
|
return json; |
|
|
|
} |
|
|
|
|
|
|
|
public readonly string text; |
|
|
|
public readonly TextSelection selection; |
|
|
|
public readonly TextRange composing; |
|
|
|
|
|
|
|
public static readonly TextEditingValue empty = new TextEditingValue(); |
|
|
|
|
|
|
|
public TextEditingValue copyWith( |
|
|
|
string text = null, |
|
|
|
|
|
|
text ?? this.text, |
|
|
|
selection ?? this.selection, |
|
|
|
composing ?? this.composing |
|
|
|
text: text ?? this.text, |
|
|
|
selection: selection ?? this.selection, |
|
|
|
composing: composing ?? this.composing |
|
|
|
//unity-specific
|
|
|
|
public TextEditingValue insert(string text) { |
|
|
|
string newText; |
|
|
|
TextSelection newSelection; |
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
//unity-specific
|
|
|
|
public TextEditingValue deleteSelection(bool backDelete = true) { |
|
|
|
if (selection.isCollapsed) { |
|
|
|
if (backDelete) { |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//unity-specific
|
|
|
|
//unity-specific
|
|
|
|
//unity-specific
|
|
|
|
//unity-specific
|
|
|
|
//unity-specific
|
|
|
|
public TextEditingValue moveExtent(int move) { |
|
|
|
int offset = selection.extentOffset + move; |
|
|
|
offset = Mathf.Max(0, offset); |
|
|
|
|
|
|
|
|
|
|
//unity-specific
|
|
|
|
public TextEditingValue moveSelection(int move) { |
|
|
|
int offset = selection.baseOffset + move; |
|
|
|
offset = Mathf.Max(0, offset); |
|
|
|
|
|
|
|
|
|
|
//unity-specific
|
|
|
|
public TextEditingValue compose(string composeText) { |
|
|
|
D.assert(!string.IsNullOrEmpty(composeText)); |
|
|
|
var composeStart = composing == TextRange.empty ? selection.start : composing.start; |
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
//unity-specific
|
|
|
|
public TextEditingValue clearCompose() { |
|
|
|
if (composing == TextRange.empty) { |
|
|
|
return this; |
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public static readonly TextEditingValue empty = new TextEditingValue(); |
|
|
|
|
|
|
|
public bool Equals(TextEditingValue other) { |
|
|
|
if (ReferenceEquals(null, other)) { |
|
|
|
return false; |
|
|
|
|
|
|
public override string ToString() { |
|
|
|
return $"Text: {text}, Selection: {selection}, Composing: {composing}"; |
|
|
|
} |
|
|
|
|
|
|
|
public static TextEditingValue fromJSON(JSONNode encoded) { |
|
|
|
return new TextEditingValue( |
|
|
|
text: encoded["text"] , |
|
|
|
selection: new TextSelection( |
|
|
|
baseOffset: encoded.GetValueOrDefault("selectionBase", defaultIndexNode).AsInt, |
|
|
|
extentOffset: encoded.GetValueOrDefault("selectionExtent", defaultIndexNode).AsInt, |
|
|
|
affinity: TextInputUtils._toTextAffinity(encoded["selectionAffinity"] ) ?? TextAffinity.downstream, |
|
|
|
isDirectional: encoded["selectionIsDirectional"] ?? false |
|
|
|
), |
|
|
|
composing: new TextRange( |
|
|
|
start: encoded.GetValueOrDefault("composingBase", defaultIndexNode).AsInt, |
|
|
|
end: encoded.GetValueOrDefault("composingExtent", defaultIndexNode).AsInt |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public interface TextSelectionDelegate { |
|
|
|
|
|
|
void performAction(TextInputAction action); |
|
|
|
|
|
|
|
void updateFloatingCursor(RawFloatingCursorPoint point); |
|
|
|
|
|
|
|
RawInputKeyResponse globalInputKeyHandler(RawKeyEvent evt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public enum TextInputAction { |
|
|
|
none, |
|
|
|
unspecified, |
|
|
|
done, |
|
|
|
go, |
|
|
|
search, |
|
|
|
send, |
|
|
|
next, |
|
|
|
previous, |
|
|
|
continueAction, |
|
|
|
join, |
|
|
|
route, |
|
|
|
emergencyCall, |
|
|
|
newline |
|
|
|
} |
|
|
|
|
|
|
|
public enum TextCapitalization { |
|
|
|
words, |
|
|
|
sentences, |
|
|
|
characters, |
|
|
|
none |
|
|
|
} |
|
|
|
|
|
|
|
public class TextInputConfiguration { |
|
|
|
public TextInputConfiguration( |
|
|
|
TextInputType inputType = null, |
|
|
|
bool obscureText = false, |
|
|
|
bool autocorrect = true, |
|
|
|
//SmartDashesType smartDashesType,
|
|
|
|
//SmartQuotesType smartQuotesType,
|
|
|
|
bool enableSuggestions = true, |
|
|
|
string actionLabel = null, |
|
|
|
TextInputAction inputAction = TextInputAction.done, |
|
|
|
ui.Brightness keyboardAppearance = ui.Brightness.light, |
|
|
|
TextCapitalization textCapitalization = TextCapitalization.none, |
|
|
|
bool unityTouchKeyboard = false |
|
|
|
) { |
|
|
|
D.assert(inputType != null); |
|
|
|
D.assert(obscureText != null); |
|
|
|
//smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
|
|
|
|
//smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
|
|
|
|
D.assert(autocorrect != null); |
|
|
|
D.assert(enableSuggestions != null); |
|
|
|
D.assert(keyboardAppearance != null); |
|
|
|
D.assert(inputAction != null); |
|
|
|
D.assert(textCapitalization != null); |
|
|
|
this.inputType = inputType ?? TextInputType.text; |
|
|
|
this.obscureText = obscureText; |
|
|
|
this.autocorrect = autocorrect; |
|
|
|
this.enableSuggestions = enableSuggestions; |
|
|
|
this.actionLabel = actionLabel; |
|
|
|
this.inputAction = inputAction; |
|
|
|
this.textCapitalization = textCapitalization; |
|
|
|
this.keyboardAppearance = keyboardAppearance; |
|
|
|
this.unityTouchKeyboard = unityTouchKeyboard; |
|
|
|
} |
|
|
|
public readonly TextInputAction inputAction; |
|
|
|
public readonly TextInputType inputType; |
|
|
|
public readonly string actionLabel; |
|
|
|
public readonly bool obscureText; |
|
|
|
public readonly bool autocorrect; |
|
|
|
//public readonly TextInputAction inputAction;
|
|
|
|
public readonly bool enableSuggestions; |
|
|
|
public readonly TextCapitalization textCapitalization; |
|
|
|
public readonly ui.Brightness keyboardAppearance; |
|
|
|
public readonly bool unityTouchKeyboard; |
|
|
|
|
|
|
|
public JSONNode toJson() { |
|
|
|
var json = new JSONObject(); |
|
|
|
json["inputType"] = inputType.toJson(); |
|
|
|
json["obscureText"] = obscureText; |
|
|
|
json["autocorrect"] = autocorrect; |
|
|
|
//'smartDashesType': smartDashesType.index.toString(),
|
|
|
|
//'smartQuotesType': smartQuotesType.index.toString(),
|
|
|
|
json["enableSuggestions"] = enableSuggestions; |
|
|
|
json["actionLabel"] = actionLabel; |
|
|
|
json["inputAction"] = inputAction.ToString(); |
|
|
|
json["unityTouchKeyboard"] = unityTouchKeyboard; |
|
|
|
json["textCapitalization"] = textCapitalization.ToString(); |
|
|
|
json["keyboardAppearance"] = keyboardAppearance.ToString(); |
|
|
|
return json; |
|
|
|
} |
|
|
|
//unity-specific
|
|
|
|
RawInputKeyResponse globalInputKeyHandler(RawKeyEvent evt); |
|
|
|
} |
|
|
|
|
|
|
|
public class TextInputConnection { |
|
|
|
|
|
|
|
|
|
|
internal Size _cachedSize; |
|
|
|
internal Matrix4 _cachedTransform; |
|
|
|
|
|
|
|
D.assert(to != null); |
|
|
|
|
|
|
|
|
|
|
|
//TextInput._instance._show();
|
|
|
|
|
|
|
|
Input.imeCompositionMode = IMECompositionMode.On; |
|
|
|
TextInput.keyboardDelegate.show(); |
|
|
|
|
|
|
D.assert(attached); |
|
|
|
TextInput.keyboardDelegate.setEditingState(value); |
|
|
|
//TextInput._instance._setEditingState(value);
|
|
|
|
|
|
|
|
//var dictionary = new JSONObject();
|
|
|
|
//json["text"] = text;
|
|
|
|
|
|
|
|
Dictionary<string,object> dictionary = new Dictionary<string, object>(); |
|
|
|
dictionary["width"] = editableBoxSize.width; |
|
|
|
dictionary["height"] = editableBoxSize.height; |
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
string fontFamily = null, |
|
|
|
float? fontSize = null, |
|
|
|
FontWeight fontWeight = null, |
|
|
|
TextDirection? textDirection = null, |
|
|
|
TextAlign? textAlign = null |
|
|
|
) { /// ????
|
|
|
|
string fontFamily, |
|
|
|
float? fontSize, |
|
|
|
FontWeight fontWeight, |
|
|
|
TextDirection textDirection, |
|
|
|
TextAlign textAlign |
|
|
|
) { |
|
|
|
dictionary["textAlignIndex"] = textAlign?.GetHashCode(); |
|
|
|
dictionary["textDirectionIndex"] = textDirection?.GetHashCode(); |
|
|
|
dictionary["textAlignIndex"] = (int)textAlign; |
|
|
|
dictionary["textDirectionIndex"] = (int)textDirection; |
|
|
|
|
|
|
|
//TextInput._instance._clearClient();
|
|
|
|
TextInput.keyboardDelegate.clearClient(); |
|
|
|
TextInput._currentConnection = null; |
|
|
|
Input.imeCompositionMode = IMECompositionMode.Auto; |
|
|
|
|
|
|
TextInput._currentConnection = null; |
|
|
|
D.assert(!attached); |
|
|
|
} |
|
|
|
|
|
|
|
internal readonly Window _window; |
|
|
|
TouchScreenKeyboard _keyboard; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
public static TextInputConnection attach(TextInputClient client, TextInputConfiguration configuration) { |
|
|
|
D.assert(client != null); |
|
|
|
D.assert(configuration != null); |
|
|
|
var connection = new TextInputConnection(client); |
|
|
|
_currentConnection = connection; |
|
|
|
if (keyboardDelegate != null) { |
|
|
|