浏览代码

scroller: code style cleanup + add addPointerScroll specifically for PointScrollEvent, avoid potential pollution on PointerEvent process pipeline

/main
xingwei.zhu 6 年前
当前提交
93a9720d
共有 12 个文件被更改,包括 65 次插入66 次删除
  1. 12
      Runtime/engine/WidgetCanvas.cs
  2. 4
      Runtime/gestures/binding.cs
  3. 10
      Runtime/gestures/converter.cs
  4. 57
      Runtime/gestures/monodrag.cs
  5. 5
      Runtime/gestures/multidrag.cs
  6. 5
      Runtime/gestures/multitap.cs
  7. 6
      Runtime/gestures/pointer_router.cs
  8. 15
      Runtime/gestures/recognizer.cs
  9. 4
      Runtime/widgets/gesture_detector.cs
  10. 10
      Runtime/widgets/scroll_activity.cs
  11. 1
      Runtime/widgets/scroll_position_with_single_context.cs
  12. 2
      Samples/UIWidgetSample/ExpansionPanelCanvas.cs

12
Runtime/engine/WidgetCanvas.cs


using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.editor;

Texture _texture;
Vector2 _lastMouseMove;
bool _mouseEntered;
const int mouseButtonNum = 3;
const int mouseScrollId = mouseButtonNum + 1;
protected override void OnEnable() {
base.OnEnable();

}
int getScrollButton() {
return 5;
return mouseScrollId;
for (int key = 0; key < 3; key++) {
for (int key = 0; key < mouseButtonNum; key++) {
if (Input.GetMouseButton(key)) {
return key;
}

4
Runtime/gestures/binding.cs


void _handlePointerScrollEvent(PointerEvent evt) {
this.pointerRouter.clearScrollRoute(evt.pointer);
this.dispatchEvent(evt, result);
}

10
Runtime/gestures/converter.cs


int _pointer;
// pointers 0 ~ 9 are preserved for special unique inputs
// special pointer id:
// mouse scroll
const int scrollPointer = 5;
public void initScrollPointer() {

var _scrollData = (ScrollData) datum;
_PointerState state = _ensureStateForPointer(datum, position);
state.initScrollPointer();
yield return new PointerScrollEvent(
timeStamp: timeStamp,
pointer: state.pointer,

);
break;
}
case PointerChange.up:
case PointerChange.cancel: {
D.assert(_pointers.ContainsKey(datum.device));

57
Runtime/gestures/monodrag.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;
namespace Unity.UIWidgets.gestures {
enum _DragState {

readonly Dictionary<int, VelocityTracker> _velocityTrackers = new Dictionary<int, VelocityTracker>();
public override void addPointer(PointerEvent evt) {
if (evt is PointerScrollEvent) {
this.startTrackingScrollerPointer(evt.pointer);
if (this._state == _DragState.ready) {
this._state = _DragState.possible;
this._initialPosition = evt.position;
if (this.onStart != null) {
this.invokeCallback<object>("onStart", () => {
this.onStart(new DragStartDetails(
sourceTimeStamp: evt.timeStamp,
globalPosition: this._initialPosition
));
return null;
});
}
public override void addScrollPointer(PointerScrollEvent evt) {
this.startTrackingScrollerPointer(evt.pointer);
if (this._state == _DragState.ready) {
this._state = _DragState.possible;
this._initialPosition = evt.position;
if (this.onStart != null) {
this.invokeCallback<object>("onStart", () => {
this.onStart(new DragStartDetails(
sourceTimeStamp: evt.timeStamp,
globalPosition: this._initialPosition
));
return null;
});
return;
}
public override void addPointer(PointerDownEvent evt) {
this.startTrackingPointer(evt.pointer);
this._velocityTrackers[evt.pointer] = new VelocityTracker();
if (this._state == _DragState.ready) {

}
this.invokeCallback<object>("onEnd", () => {
this.onEnd(new DragEndDetails(
velocity: Velocity.zero,
primaryVelocity: 0.0
));
return null;
}, debugReport: () => { return ""; }
this.onEnd(new DragEndDetails(
velocity: Velocity.zero,
primaryVelocity: 0.0
));
return null;
}, debugReport: () => { return ""; }
return;
}
if (evt is PointerMoveEvent) {

D.assert(tracker != null);
var estimate = tracker.getVelocityEstimate();
//if (estimate != null && this._isFlingGesture(estimate) || pointer == 5) {
// Offset ret = pointer == 5 ? new Offset(0, 1) : estimate.pixelsPerSecond;
Offset ret = estimate.pixelsPerSecond;
Velocity velocity = new Velocity(pixelsPerSecond: ret)
Velocity velocity = new Velocity(pixelsPerSecond: estimate.pixelsPerSecond)
.clampMagnitude(this.minFlingVelocity ?? Constants.kMinFlingVelocity,
this.maxFlingVelocity ?? Constants.kMaxFlingVelocity);
this.invokeCallback<object>("onEnd", () => {

5
Runtime/gestures/multidrag.cs


Dictionary<int, T> _pointers = new Dictionary<int, T>();
public override void addPointer(PointerEvent pEvent) {
public override void addPointer(PointerDownEvent pEvent) {
D.assert(pEvent is PointerDownEvent);
T state = this.createNewPointerState((PointerDownEvent)pEvent);
T state = this.createNewPointerState(pEvent);
this._pointers[pEvent.pointer] = state;
GestureBinding.instance.pointerRouter.addRoute(pEvent.pointer, this._handleEvent);
state._setArenaEntry(GestureBinding.instance.gestureArena.add(pEvent.pointer, this));

5
Runtime/gestures/multitap.cs


_TapTracker _firstTap;
readonly Dictionary<int, _TapTracker> _trackers = new Dictionary<int, _TapTracker>();
public override void addPointer(PointerEvent evt) {
D.assert(evt is PointerDownEvent);
public override void addPointer(PointerDownEvent evt) {
if (this._firstTap != null &&
!this._firstTap.isWithinTolerance(evt, Constants.kDoubleTapSlop)) {
return;

_TapTracker tracker = new _TapTracker(
evt: (PointerDownEvent)evt,
evt: evt,
entry: GestureBinding.instance.gestureArena.add(evt.pointer, this)
);
this._trackers[evt.pointer] = tracker;

6
Runtime/gestures/pointer_router.cs


public void addRoute(int pointer, PointerRoute route) {
var routes = this._routeMap.putIfAbsent(pointer, () => new HashSet<PointerRoute>());
//D.assert(!routes.Contains(route));
if (!routes.Contains(route)) {
routes.Add(route);
}
D.assert(!routes.Contains(route));
routes.Add(route);
}
public void removeRoute(int pointer, PointerRoute route) {

15
Runtime/gestures/recognizer.cs


public readonly object debugOwner;
public abstract void addPointer(PointerEvent evt);
public abstract void addPointer(PointerDownEvent evt);
public virtual void addScrollPointer(PointerScrollEvent evt) {
}
public virtual void dispose() {
}

readonly Dictionary<int, GestureArenaEntry> _entries = new Dictionary<int, GestureArenaEntry>();
protected readonly HashSet<int> _trackedPointers = new HashSet<int>();
readonly HashSet<int> _trackedPointers = new HashSet<int>();
protected abstract void handleEvent(PointerEvent evt);

protected void startTrackingPointer(int pointer) {
GestureBinding.instance.pointerRouter.addRoute(pointer, this.handleEvent);
this._trackedPointers.Add(pointer);
//D.assert(!this._entries.ContainsKey(pointer));
if (!this._entries.ContainsKey(pointer)) {
this._entries[pointer] = this._addPointerToArena(pointer);
}
D.assert(!this._entries.ContainsKey(pointer));
this._entries[pointer] = this._addPointerToArena(pointer);
}
protected void stopTrackingPointer(int pointer) {

Timer _timer;
public override void addPointer(PointerEvent evt) {
public override void addPointer(PointerDownEvent evt) {
this.startTrackingPointer(evt.pointer);
if (this.state == GestureRecognizerState.ready) {
this.state = GestureRecognizerState.possible;

4
Runtime/widgets/gesture_detector.cs


recognizer.addPointer(evt);
}
}
recognizer.addPointer(evt);
recognizer.addScrollPointer(evt);
}
}

10
Runtime/widgets/scroll_activity.cs


D.assert(details.primaryDelta != null);
this._lastDetails = details;
double offset = details.primaryDelta.Value;
if (details.isScroll) {
if (offset == 0.0) {
return;

offset = -offset;
}
if (offset != 0.0) {
this._lastNonStationaryTimestamp = details.sourceTimeStamp;
}

1
Runtime/widgets/scroll_position_with_single_context.cs


if (pixel > this.maxScrollExtent) {
pixel = this.maxScrollExtent;
}
this.setPixels(pixel);
}

2
Samples/UIWidgetSample/ExpansionPanelCanvas.cs


namespace UIWidgetsSample {
public class ExpansionPanelCanvas : WidgetCanvas {
int testCaseId = 0;
int testCaseId = 1;
readonly List<Widget> testCases = new List<Widget> {
new SingleChildScrollWidget(),

正在加载...
取消
保存