浏览代码

fix widget

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
cbbb4171
共有 17 个文件被更改,包括 245 次插入135 次删除
  1. 1
      com.unity.uiwidgets/Runtime/rendering/editable.cs
  2. 182
      com.unity.uiwidgets/Runtime/service/text_editing.cs
  3. 4
      com.unity.uiwidgets/Runtime/service/text_input.cs
  4. 89
      com.unity.uiwidgets/Runtime/ui2/window.cs
  5. 4
      com.unity.uiwidgets/Runtime/widgets/automatic_keep_alive.cs
  6. 1
      com.unity.uiwidgets/Runtime/widgets/basic.cs
  7. 12
      com.unity.uiwidgets/Runtime/widgets/binding.cs
  8. 17
      com.unity.uiwidgets/Runtime/widgets/editable_text.cs
  9. 8
      com.unity.uiwidgets/Runtime/widgets/focus_manager.cs
  10. 1
      com.unity.uiwidgets/Runtime/widgets/media_query.cs
  11. 9
      com.unity.uiwidgets/Runtime/widgets/overscroll_indicator.cs
  12. 6
      com.unity.uiwidgets/Runtime/widgets/scrollable.cs
  13. 16
      com.unity.uiwidgets/Runtime/widgets/selectable_text.cs
  14. 1
      com.unity.uiwidgets/Runtime/widgets/text.cs
  15. 20
      com.unity.uiwidgets/Runtime/widgets/text_selection.cs
  16. 3
      com.unity.uiwidgets/Runtime/widgets/texture.cs
  17. 6
      com.unity.uiwidgets/Runtime/widgets/widget_inspector.cs

1
com.unity.uiwidgets/Runtime/rendering/editable.cs


using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using StrutStyle = Unity.UIWidgets.painting.StrutStyle;
namespace Unity.UIWidgets.rendering {
class EditableUtils {

182
com.unity.uiwidgets/Runtime/service/text_editing.cs


using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.service {
public class TextRange : IEquatable<TextRange> {
public readonly int start;
public readonly int end;
public static TextRange collapsed(int offset) {
D.assert(offset >= -1);
return new TextRange(offset, offset);
}
public static readonly TextRange empty = new TextRange(-1, -1);
public TextRange(int start, int end) {
D.assert(start >= -1);
D.assert(end >= -1);
this.start = start;
this.end = end;
}
public bool isValid {
get { return start >= 0 && end >= 0; }
}
public bool isCollapsed {
get { return start == end; }
}
public bool isNormalized {
get { return start <= end; }
}
public string textBefore(string text) {
D.assert(isNormalized);
return text.Substring(0, start);
}
public string textAfter(string text) {
D.assert(isNormalized);
return text.Substring(end);
}
public string textInside(string text) {
D.assert(isNormalized);
return text.Substring(start, end - start);
}
public bool Equals(TextRange other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return start == other.start && end == other.end;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != GetType()) {
return false;
}
return Equals((TextRange) obj);
}
public override int GetHashCode() {
unchecked {
return (start * 397) ^ end;
}
}
public static bool operator ==(TextRange left, TextRange right) {
return Equals(left, right);
}
public static bool operator !=(TextRange left, TextRange right) {
return !Equals(left, right);
}
public override string ToString() {
return $"TextRange Start: {start}, End: {end}";
}
}
// public class TextRange : IEquatable<TextRange> {
// public readonly int start;
// public readonly int end;
//
// public static TextRange collapsed(int offset) {
// D.assert(offset >= -1);
// return new TextRange(offset, offset);
// }
//
// public static readonly TextRange empty = new TextRange(-1, -1);
//
// public TextRange(int start, int end) {
// D.assert(start >= -1);
// D.assert(end >= -1);
// this.start = start;
// this.end = end;
// }
//
// public bool isValid {
// get { return start >= 0 && end >= 0; }
// }
//
// public bool isCollapsed {
// get { return start == end; }
// }
//
// public bool isNormalized {
// get { return start <= end; }
// }
//
// public string textBefore(string text) {
// D.assert(isNormalized);
// return text.Substring(0, start);
// }
//
// public string textAfter(string text) {
// D.assert(isNormalized);
// return text.Substring(end);
// }
//
// public string textInside(string text) {
// D.assert(isNormalized);
// return text.Substring(start, end - start);
// }
//
// public bool Equals(TextRange other) {
// if (ReferenceEquals(null, other)) {
// return false;
// }
//
// if (ReferenceEquals(this, other)) {
// return true;
// }
//
// return start == other.start && end == other.end;
// }
//
// public override bool Equals(object obj) {
// if (ReferenceEquals(null, obj)) {
// return false;
// }
//
// if (ReferenceEquals(this, obj)) {
// return true;
// }
//
// if (obj.GetType() != GetType()) {
// return false;
// }
//
// return Equals((TextRange) obj);
// }
//
// public override int GetHashCode() {
// unchecked {
// return (start * 397) ^ end;
// }
// }
//
// public static bool operator ==(TextRange left, TextRange right) {
// return Equals(left, right);
// }
//
// public static bool operator !=(TextRange left, TextRange right) {
// return !Equals(left, right);
// }
//
// public override string ToString() {
// return $"TextRange Start: {start}, End: {end}";
// }
// }
public class TextSelection : TextRange, IEquatable<TextSelection> {
public readonly int baseOffset;

4
com.unity.uiwidgets/Runtime/service/text_input.cs


class TextInputConfiguration {
public TextInputConfiguration(TextInputType inputType = null,
bool obscureText = false, bool autocorrect = true, TextInputAction inputAction = TextInputAction.done,
Brightness keyboardAppearance = Brightness.light,
ui.Brightness keyboardAppearance = ui.Brightness.light,
TextCapitalization textCapitalization = TextCapitalization.none,
bool unityTouchKeyboard = false) {
this.inputType = inputType ?? TextInputType.text;

public readonly bool autocorrect;
public readonly TextInputAction inputAction;
public readonly TextCapitalization textCapitalization;
public readonly Brightness keyboardAppearance;
public readonly ui.Brightness keyboardAppearance;
public readonly bool unityTouchKeyboard;
public JSONNode toJson() {

89
com.unity.uiwidgets/Runtime/ui2/window.cs


}
}
public class Locale : IEquatable<Locale> {
public Locale(string languageCode, string countryCode = null) {
D.assert(languageCode != null);

public Locale(string languageCode, string countryCode = null, string scriptCode = null) {
D.assert(languageCode != null);
_languageCode = languageCode;
_countryCode = countryCode;
_scriptCode = scriptCode;
}
public static Locale fromSubtags(
string languageCode = "und",
string scriptCode = null,
string countryCode = null
) {
D.assert(languageCode != null); // ignore: unnecessary_null_comparison
D.assert(languageCode != "");
D.assert(scriptCode != "");
D.assert(countryCode != "");
return new Locale(languageCode, countryCode, scriptCode);
}
readonly string _languageCode;
public string languageCode {

get { return _countryCode; }
}
readonly string _scriptCode;
public string scriptCode { get; }
public bool Equals(Locale other) {
if (ReferenceEquals(null, other)) {
return false;

return $"{languageCode}_{countryCode}";
}
}
public class Window {
internal IntPtr _ptr;
internal object _binding;

public VoidCallback onMetricsChanged { get; set; }
public Locale locale {
get {
if (_locales != null && _locales.isNotEmpty()) {
return _locales.first();
}
return null;
}
}
List<Locale> _locales;
public List<Locale> locales { get; }
Locale computePlatformResolvedLocale(List<Locale> supportedLocales) {
List<string> supportedLocalesData = new List<string>();
foreach (Locale locale in supportedLocales) {
supportedLocalesData.Add(locale.languageCode);
supportedLocalesData.Add(locale.countryCode);
supportedLocalesData.Add(locale.scriptCode);
}
List<string> result = _computePlatformResolvedLocale(supportedLocalesData);
if (result.isNotEmpty()) {
return Locale.fromSubtags(
languageCode: result[0],
countryCode: result[1] == "" ? null : result[1],
scriptCode: result[2] == "" ? null : result[2]);
}
return null;
}
List<string> _computePlatformResolvedLocale(List<string> supportedLocalesData) =>
Window_computePlatformResolvedLocale(supportedLocalesData);
/// A callback that is invoked whenever [locale] changes value.
///
/// The framework invokes this callback in the same zone in which the
/// callback was set.
///
/// See also:
///
/// * [WidgetsBindingObserver], for a mechanism at the widgets layer to
/// observe when this callback is invoked.
public VoidCallback onLocaleChanged {
get { return _onLocaleChanged; }
set {
_onLocaleChanged = value;
_onLocaleChangedZone = Zone.current;
}
}
VoidCallback _onLocaleChanged;
Zone _onLocaleChangedZone = Zone.root;
public string initialLifecycleState {
get {
_initialLifecycleStateAccessed = true;

[DllImport(NativeBindings.dllName)]
static extern void Window_freeDefaultRouteName(IntPtr routeNamePtr);
[DllImport(NativeBindings.dllName)]
static extern List<string> Window_computePlatformResolvedLocale(List<string> supportedLocalesData);
[MonoPInvokeCallback(typeof(Window_sendPlatformMessageCallback))]
static unsafe void _sendPlatformMessageCallback(IntPtr callbackHandle, byte* data, int dataLength) {

4
com.unity.uiwidgets/Runtime/widgets/automatic_keep_alive.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.ui;

}
else {
_keepingAlive = false;
Window.instance.scheduleMicrotask(() => {
async_.scheduleMicrotask(() => {
return null;
});
}
}

1
com.unity.uiwidgets/Runtime/widgets/basic.cs


using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using StrutStyle = Unity.UIWidgets.painting.StrutStyle;
namespace Unity.UIWidgets.widgets {
public class Directionality : InheritedWidget {

12
com.unity.uiwidgets/Runtime/widgets/binding.cs


buildOwner.onBuildScheduled = _handleBuildScheduled;
Window.instance.onLocaleChanged += handleLocaleChanged;
widgetInspectorService = new WidgetInspectorService(this);
addPersistentFrameCallback((duration) => {
TextBlobMesh.tickNextFrame();
TessellationGenerator.tickNextFrame();
uiTessellationGenerator.tickNextFrame();
uiPathCacheManager.tickNextFrame();
});
// addPersistentFrameCallback((duration) => {
// TextBlobMesh.tickNextFrame();
// TessellationGenerator.tickNextFrame();
// uiTessellationGenerator.tickNextFrame();
// uiPathCacheManager.tickNextFrame();
// });
}
public BuildOwner buildOwner {

17
com.unity.uiwidgets/Runtime/widgets/editable_text.cs


using System.Collections.Generic;
using RSG;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;

using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using UnityEngine;
using Brightness = Unity.UIWidgets.ui.Brightness;
using StrutStyle = Unity.UIWidgets.painting.StrutStyle;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.widgets {

int _obscureShowCharTicksPending = 0;
int _obscureLatestCharIndex;
void _cursorTick() {
object _cursorTick(object timer) {
_targetCursorVisibility = !_unityKeyboard() && !_targetCursorVisibility;
float targetOpacity = _targetCursorVisibility ? 1.0f : 0.0f;
if (widget.cursorOpacityAnimates) {

if (_obscureShowCharTicksPending > 0) {
setState(() => { _obscureShowCharTicksPending--; });
}
return null;
void _cursorWaitForStart() {
object _cursorWaitForStart(object timer) {
_cursorTimer = Window.instance.run(_kCursorBlinkHalfPeriod, _cursorTick, periodic: true);
_cursorTimer = Timer.periodic(_kCursorBlinkHalfPeriod, _cursorTick);
return null;
}
void _startCursorTimer() {

if (widget.cursorOpacityAnimates) {
_cursorTimer =
Window.instance.run(_kCursorBlinkWaitForStart, _cursorWaitForStart, periodic: true);
Timer.periodic(_kCursorBlinkWaitForStart, _cursorWaitForStart);
_cursorTimer = Window.instance.run(_kCursorBlinkHalfPeriod, _cursorTick, periodic: true);
_cursorTimer = Timer.periodic(_kCursorBlinkHalfPeriod, _cursorTick);
}
}

8
com.unity.uiwidgets/Runtime/widgets/focus_manager.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;

var focusPath = _manager?._getCurrentFocusPath();
if (_focus == node &&
(_focusPath == focusPath || (focusPath != null && _focusPath != null &&
_focusPath.SequenceEqual(focusPath)))) {
_focusPath.SequenceEqual(focusPath)))) {
return;
}

}
_haveScheduledUpdate = true;
Window.instance.scheduleMicrotask(_update);
async_.scheduleMicrotask(() => {
_update();
return null;
});
}
internal FocusNode _findNextFocus() {

1
com.unity.uiwidgets/Runtime/widgets/media_query.cs


using Unity.UIWidgets.painting;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Brightness = Unity.UIWidgets.ui.Brightness;
namespace Unity.UIWidgets.widgets {
public enum Orientation {

9
com.unity.uiwidgets/Runtime/widgets/overscroll_indicator.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.physics;

}
_pullRecedeTimer =
Window.instance.run(_pullHoldTime, () => _recede(_pullDecayTime));
Timer.create(_pullHoldTime, () => {
_recede(_pullDecayTime);
return null;
});
}
public void scrollEnd() {

if (_displacementTickerLastElapsed != null) {
float? t = elapsed.Milliseconds - _displacementTickerLastElapsed?.Milliseconds;
_displacement = _displacementTarget - (_displacementTarget - _displacement) *
Mathf.Pow(2.0f, (-t ?? 0.0f) / _crossAxisHalfTime.Milliseconds);
Mathf.Pow(2.0f, (-t ?? 0.0f) / _crossAxisHalfTime.Milliseconds);
notifyListeners();
}

6
com.unity.uiwidgets/Runtime/widgets/scrollable.cs


using System.Linq;
using RSG;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;

controller.detach(oldPosition);
}
Window.instance.scheduleMicrotask(oldPosition.dispose);
async_.scheduleMicrotask(()=> {
oldPosition.dispose();
return null;
});
}
_position = controller == null

16
com.unity.uiwidgets/Runtime/widgets/selectable_text.cs


using System;
using System.Collections.Generic;
using RSG;
using Unity.UIWidgets.async;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;

public void didChangeTextScaleFactor() {
}
public void didChangePlatformBrightness() {
}

}
_lastTapOffset = details.globalPosition;
_doubleTapTimer = Window.instance.run(Constants.kDoubleTapTimeout, _doubleTapTimeout);
_doubleTapTimer = Timer.create(Constants.kDoubleTapTimeout, _doubleTapTimeout);
}
_isDoubleTap = false;

void _handleDragUpdate(DragUpdateDetails details) {
_lastDragUpdateDetails = details;
_dragUpdateThrottleTimer = _dragUpdateThrottleTimer ??
Window.instance.run(TextSelectionUtils._kDragSelectionUpdateThrottle,
_handleDragUpdateThrottled);
Timer.create(TextSelectionUtils._kDragSelectionUpdateThrottle,
_handleDragUpdateThrottled);
void _handleDragUpdateThrottled() {
object _handleDragUpdateThrottled() {
D.assert(_lastDragStartDetails != null);
D.assert(_lastDragUpdateDetails != null);
if (widget.onDragSelectionUpdate != null) {

_dragUpdateThrottleTimer = null;
_lastDragUpdateDetails = null;
return null;
}
void _handleDragEnd(DragEndDetails details) {

}
}
void _doubleTapTimeout() {
object _doubleTapTimeout() {
return null;
}
bool _isWithinDoubleTapTolerance(Offset secondTapOffset) {

1
com.unity.uiwidgets/Runtime/widgets/text.cs


using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using StrutStyle = Unity.UIWidgets.painting.StrutStyle;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.widgets {

20
com.unity.uiwidgets/Runtime/widgets/text_selection.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.rendering;

using Rect = Unity.UIWidgets.ui.Rect;
using TextRange = Unity.UIWidgets.ui.TextRange;
namespace Unity.UIWidgets.widgets {
static class TextSelectionUtils {

offset: value.selection.start + data.text.Length
)
);
selectionDelegate.bringIntoView(selectionDelegate.textEditingValue.selection.extendPos);
selectionDelegate.hideToolbar();
}

void _handleDragStart(DragStartDetails details) {
_dragPosition = details.globalPosition +
new Offset(0.0f, -widget.selectionControls.handleSize.height);
new Offset(0.0f, -widget.selectionControls.handleSize.height);
}
void _handleDragUpdate(DragUpdateDetails details) {

}
_lastTapOffset = details.globalPosition;
_doubleTapTimer = Window.instance.run(Constants.kDoubleTapTimeout, _doubleTapTimeout);
_doubleTapTimer = Timer.create(Constants.kDoubleTapTimeout, _doubleTapTimeout);
}
_isDoubleTap = false;

void _handleDragUpdate(DragUpdateDetails details) {
_lastDragUpdateDetails = details;
_dragUpdateThrottleTimer = _dragUpdateThrottleTimer ??
Window.instance.run(TextSelectionUtils._kDragSelectionUpdateThrottle,
_handleDragUpdateThrottled);
_dragUpdateThrottleTimer =
_dragUpdateThrottleTimer ?? Timer.create(TextSelectionUtils._kDragSelectionUpdateThrottle, _handleDragUpdateThrottled);
void _handleDragUpdateThrottled() {
object _handleDragUpdateThrottled() {
D.assert(_lastDragStartDetails != null);
D.assert(_lastDragUpdateDetails != null);
if (widget.onDragSelectionUpdate != null) {

_dragUpdateThrottleTimer = null;
_lastDragUpdateDetails = null;
return null;
}
void _handleDragEnd(DragEndDetails details) {

_isDoubleTap = false;
}
void _doubleTapTimeout() {
object _doubleTapTimeout() {
return null;
}
bool _isWithinDoubleTapTolerance(Offset secondTapOffset) {

3
com.unity.uiwidgets/Runtime/widgets/texture.cs


if (instance == null) {
WindowAdapter.windowAdapters.ForEach(w => w.scheduleFrame(false));
} else {
instance.scheduleFrame(false);
// TODO: check whether following is needed
// instance.scheduleFrame(false);
}
}

6
com.unity.uiwidgets/Runtime/widgets/widget_inspector.cs


Picture _buildPicture(_InspectorOverlayRenderState state) {
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new RecorderCanvas(recorder);
Canvas canvas = new Canvas(recorder, state.overlayRect);
Size size = state.overlayRect.size;
var fillPaint = new Paint() {color = _kHighlightedRenderObjectFillColor};

};
Rect selectedPaintRect = state.selected.rect.deflate(0.5f);
canvas.save();
canvas.setMatrix(state.selected.transform.toMatrix3());
canvas.transform(state.selected.transform._m4storage);
canvas.drawRect(selectedPaintRect, fillPaint);
canvas.drawRect(selectedPaintRect, borderPaint);
canvas.restore();

canvas.setMatrix(transformedRect.transform.toMatrix3());
canvas.transform(transformedRect.transform._m4storage);
canvas.drawRect(transformedRect.rect.deflate(0.5f), borderPaint);
canvas.restore();
}

正在加载...
取消
保存