浏览代码

Complete widgets.

/main
Yuncong Zhang 5 年前
当前提交
956472c7
共有 5 个文件被更改,包括 173 次插入24 次删除
  1. 140
      Runtime/gestures/long_press.cs
  2. 24
      Runtime/gestures/recognizer.cs
  3. 4
      Runtime/widgets/editable_text.cs
  4. 25
      Runtime/widgets/focus_manager.cs
  5. 4
      Runtime/widgets/gesture_detector.cs

140
Runtime/gestures/long_press.cs


using System;
public delegate void GestureLongPressUpCallback();
public delegate void GestureLongPressDragStartCallback(GestureLongPressDragStartDetails details);
public delegate void GestureLongPressDragUpdateCallback(GestureLongPressDragUpdateDetails details);
public delegate void GestureLongPressDragUpCallback(GestureLongPressDragUpDetails details);
public class GestureLongPressDragStartDetails {
public GestureLongPressDragStartDetails(
TimeSpan? sourceTimeStamp = null,
Offset globalPosition = null
) {
this.sourceTimeStamp = sourceTimeStamp;
this.globalPosition = globalPosition ?? Offset.zero;
}
public readonly TimeSpan? sourceTimeStamp;
public readonly Offset globalPosition;
}
public class GestureLongPressDragUpdateDetails {
public GestureLongPressDragUpdateDetails(
TimeSpan? sourceTimeStamp = null,
Offset globalPosition = null,
Offset offsetFromOrigin = null
) {
this.sourceTimeStamp = sourceTimeStamp;
this.globalPosition = globalPosition ?? Offset.zero;
this.offsetFromOrigin = offsetFromOrigin ?? Offset.zero;
}
public readonly TimeSpan? sourceTimeStamp;
public readonly Offset globalPosition;
public readonly Offset offsetFromOrigin;
}
public class GestureLongPressDragUpDetails {
public GestureLongPressDragUpDetails(
TimeSpan? sourceTimeStamp = null,
Offset globalPosition = null
) {
this.sourceTimeStamp = sourceTimeStamp;
this.globalPosition = globalPosition ?? Offset.zero;
}
public readonly TimeSpan? sourceTimeStamp;
public readonly Offset globalPosition;
}
public class LongPressGestureRecognizer : PrimaryPointerGestureRecognizer {
public LongPressGestureRecognizer(object debugOwner = null, PointerDeviceKind? kind = null) :
base(deadline: Constants.kLongPressTimeout, debugOwner: debugOwner, kind: kind) {

public override string debugDescription {
get { return "long press"; }
}
}
public class LongPressDragGestureRecognizer : PrimaryPointerGestureRecognizer {
public LongPressDragGestureRecognizer(object debugOwner = null) : base(
deadline: Constants.kLongPressTimeout,
postAcceptSlopTolerance: null,
debugOwner: debugOwner
) {
}
bool _longPressAccepted = false;
Offset _longPressOrigin;
TimeSpan? _longPressStartTimestamp;
public GestureLongPressDragStartCallback onLongPressStart;
public GestureLongPressDragUpdateCallback onLongPressDragUpdate;
public GestureLongPressDragUpCallback onLongPressUp;
protected override void didExceedDeadline() {
this.resolve(GestureDisposition.accepted);
this._longPressAccepted = true;
base.acceptGesture(this.primaryPointer);
if (this.onLongPressStart != null) {
this.invokeCallback<object>("onLongPressStart", () => {
this.onLongPressStart(new GestureLongPressDragStartDetails(
sourceTimeStamp: this._longPressStartTimestamp,
globalPosition: this._longPressOrigin
));
return null;
});
}
}
protected override void handlePrimaryPointer(PointerEvent e) {
if (e is PointerUpEvent) {
if (this._longPressAccepted == true && this.onLongPressUp != null) {
this._longPressAccepted = false;
this.invokeCallback<object>("onLongPressUp", () => {
this.onLongPressUp(new GestureLongPressDragUpDetails(
sourceTimeStamp: e.timeStamp,
globalPosition: e.position
));
return null;
});
}
else {
this.resolve(GestureDisposition.rejected);
}
}
else if (e is PointerDownEvent) {
this._longPressAccepted = false;
this._longPressStartTimestamp = e.timeStamp;
this._longPressOrigin = e.position;
}
else if (e is PointerMoveEvent && this._longPressAccepted && this.onLongPressDragUpdate != null) {
this.invokeCallback<object>("onLongPressDrag", () => {
this.onLongPressDragUpdate(new GestureLongPressDragUpdateDetails(
sourceTimeStamp: e.timeStamp,
globalPosition: e.position,
offsetFromOrigin: e.position - this._longPressOrigin
));
return null;
});
}
}
public override void acceptGesture(int pointer) {
}
protected override void didStopTrackingLastPointer(int pointer) {
this._longPressAccepted = false;
this._longPressOrigin = null;
this._longPressStartTimestamp = null;
base.didStopTrackingLastPointer(pointer);
}
public override string debugDescription {
get { return "long press drag"; }
}
}
}

24
Runtime/gestures/recognizer.cs


TimeSpan? deadline = null,
object debugOwner = null,
PointerDeviceKind? kind = null,
float? preAcceptSlotTolerance = Constants.kTouchSlop,
float? postAcceptSlotTolerance = Constants.kTouchSlop
float? preAcceptSlopTolerance = Constants.kTouchSlop,
float? postAcceptSlopTolerance = Constants.kTouchSlop
D.assert(preAcceptSlotTolerance == null || preAcceptSlotTolerance >= 0,
D.assert(preAcceptSlopTolerance == null || preAcceptSlopTolerance >= 0,
D.assert(postAcceptSlotTolerance == null || postAcceptSlotTolerance >= 0,
D.assert(postAcceptSlopTolerance == null || postAcceptSlopTolerance >= 0,
this.preAcceptSlotTolerance = preAcceptSlotTolerance;
this.postAcceptSlotTolerance = postAcceptSlotTolerance;
this.preAcceptSlopTolerance = preAcceptSlopTolerance;
this.postAcceptSlopTolerance = postAcceptSlopTolerance;
public readonly float? preAcceptSlotTolerance;
public readonly float? preAcceptSlopTolerance;
public readonly float? postAcceptSlotTolerance;
public readonly float? postAcceptSlopTolerance;
public GestureRecognizerState state = GestureRecognizerState.ready;

if (evt.pointer == this.primaryPointer) {
bool isPreAcceptSlopPastTolerance = this.state == GestureRecognizerState.possible &&
this.preAcceptSlotTolerance != null &&
this._getDistance(evt) > this.preAcceptSlotTolerance;
this.preAcceptSlopTolerance != null &&
this._getDistance(evt) > this.preAcceptSlopTolerance;
this.postAcceptSlotTolerance != null &&
this._getDistance(evt) > this.postAcceptSlotTolerance;
this.postAcceptSlopTolerance != null &&
this._getDistance(evt) > this.postAcceptSlopTolerance;
if (evt is PointerMoveEvent && (isPreAcceptSlopPastTolerance || isPostAcceptSlopPastTolerance)) {
this.resolve(GestureDisposition.rejected);

4
Runtime/widgets/editable_text.cs


using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler;

D.assert(style != null);
D.assert(cursorColor != null);
D.assert(maxLines == null || maxLines > 0);
D.assert(backgroundCursorColor != null);
// D.assert(backgroundCursorColor != null); // TODO: remove comment
this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline);
this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f);

this.textInputAction = textInputAction;
this.textCapitalization = textCapitalization;
this.cursorColor = cursorColor;
this.backgroundCursorColor = backgroundCursorColor ?? Colors.transparent; // TODO: remove ??
this.maxLines = maxLines;
this.autofocus = autofocus;
this.selectionColor = selectionColor;

25
Runtime/widgets/focus_manager.cs


using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;
namespace Unity.UIWidgets.widgets {
public class FocusNode : ChangeNotifier {

public bool isFirstFocus {
get { return this._parent == null || this._parent._firstChild == this; }
}
List<FocusScopeNode> nodes = new List<FocusScopeNode>{this};
List<FocusScopeNode> nodes = new List<FocusScopeNode> {this};
while(node != null && node != this._manager?.rootScope) {
while (node != null && node != this._manager?.rootScope) {
return nodes;
}

public void requestFocus(FocusNode node) {
D.assert(node != null);
if (this._focus == node && this._focusPath.SequenceEqual(this._manager?._getCurrentFocusPath())) {
var focusPath = this._manager?._getCurrentFocusPath();
if (this._focus == node &&
(this._focusPath == focusPath || (focusPath != null && this._focusPath != null &&
this._focusPath.SequenceEqual(focusPath)))) {
return;
}

public FocusNode currentFocus {
get { return this._currentFocus; }
}
internal FocusNode _currentFocus;
internal void _willDisposeFocusNode(FocusNode node) {

this._currentFocus._notify();
}
}
internal List<FocusScopeNode> _getCurrentFocusPath() => this._currentFocus?._parent?._getFocusPath();
internal List<FocusScopeNode> _getCurrentFocusPath() {
return this._currentFocus?._parent?._getFocusPath();
}
public void focusNone(bool focus) {
if (focus) {

this.rootScope.setFirstFocus(this._noneScope);
}
else {

public override string ToString() {
var status = this._haveScheduledUpdate ? " UPDATE SCHEDULED" : "";
var indent = " ";

4
Runtime/widgets/gesture_detector.cs


}
if (this.onLongPressDragStart != null || this.onLongPressDragUpdate != null || this.onLongPressDragUp != null) {
gestures[LongPressDragGestureRecognizer] = new GestureRecognizerFactoryWithHandlers<LongPressDragGestureRecognizer>(
() => LongPressDragGestureRecognizer(debugOwner: this),
gestures[typeof(LongPressDragGestureRecognizer)] = new GestureRecognizerFactoryWithHandlers<LongPressDragGestureRecognizer>(
() => new LongPressDragGestureRecognizer(debugOwner: this),
(LongPressDragGestureRecognizer instance) => {
instance.onLongPressStart = this.onLongPressDragStart;
instance.onLongPressDragUpdate = this.onLongPressDragUpdate;

正在加载...
取消
保存