浏览代码

Merge branch 'material' into 'master'

Mouse scroll bug fix

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!57
/main
Shenhua Gu 6 年前
当前提交
514b30d1
共有 8 个文件被更改,包括 158 次插入35 次删除
  1. 40
      Runtime/editor/editor_window.cs
  2. 23
      Runtime/engine/WidgetCanvas.cs
  3. 8
      Runtime/gestures/binding.cs
  4. 16
      Runtime/gestures/monodrag.cs
  5. 2
      Runtime/ui/txt/paragraph.cs
  6. 12
      Runtime/widgets/sliver.cs
  7. 81
      Runtime/editor/scroll_input.cs
  8. 11
      Runtime/editor/scroll_input.cs.meta

40
Runtime/editor/editor_window.cs


readonly TimerProvider _timerProvider = new TimerProvider();
readonly TextInput _textInput = new TextInput();
readonly Rasterizer _rasterizer = new Rasterizer();
readonly ScrollInput _scrollInput = new ScrollInput();
bool _regenerateLayerTree;
Surface _surface;

);
}
else if (evt.type == EventType.ScrollWheel) {
pointerData = new ScrollData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scroll,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio,
scrollX: -evt.delta.x,
scrollY: -evt.delta.y
this._scrollInput.onScroll((float) (-evt.delta.x * this._devicePixelRatio),
(float) (-evt.delta.y * this._devicePixelRatio),
(float) (evt.mousePosition.x * this._devicePixelRatio),
(float) (evt.mousePosition.y * this._devicePixelRatio),
evt.button
);
}

}
}
void _updateScrollInput() {
var deltaScroll = this._scrollInput.getScrollDelta();
if (deltaScroll == Vector2.zero) {
return;
}
PointerData pointerData = new ScrollData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scroll,
kind: PointerDeviceKind.mouse,
device: this._scrollInput.getDeviceId(),
physicalX: this._scrollInput.getPointerPosX(),
physicalY: this._scrollInput.getPointerPosY(),
scrollX: deltaScroll.x,
scrollY: deltaScroll.y
);
this.onPointerEvent(new PointerDataPacket(new List<PointerData> {
pointerData
}));
}
this._updateScrollInput();
if (this._textInput != null) {
this._textInput.keyboardManager.Update();
}

23
Runtime/engine/WidgetCanvas.cs


const int mouseButtonNum = 3;
const int mouseScrollId = mouseButtonNum + 1;
readonly ScrollInput _scrollInput = new ScrollInput();
protected override void OnEnable() {
base.OnEnable();

}
if (this._mouseEntered) {
if (Input.mouseScrollDelta.y != 0) {
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) {
this._scrollInput.onScroll((float) (Input.mouseScrollDelta.x * this.pixelRatio),
(float) (Input.mouseScrollDelta.y * this.pixelRatio),
pos.x,
pos.y,
this.getScrollButton());
}
var deltaScroll = this._scrollInput.getScrollDelta();
if (deltaScroll != Vector2.zero) {
device: this.getScrollButton(),
physicalX: pos.x,
physicalY: pos.y,
scrollX: Input.mouseScrollDelta.x,
scrollY: Input.mouseScrollDelta.y * 5
device: this._scrollInput.getDeviceId(),
physicalX: this._scrollInput.getPointerPosX(),
physicalY: this._scrollInput.getPointerPosY(),
scrollX: deltaScroll.x,
scrollY: deltaScroll.y
));
}
}

8
Runtime/gestures/binding.cs


public readonly HashSet<HitTestTarget> lastMoveTargets = new HashSet<HitTestTarget>();
void _handlePointerEvent(PointerEvent evt) {
if (evt is PointerHoverEvent) {
this._handlePointerHoverEvent(evt);
}
}
if (evt is PointerHoverEvent) {
this._handlePointerHoverEvent(evt);
}
HitTestResult result;

16
Runtime/gestures/monodrag.cs


protected override void handleEvent(PointerEvent evt) {
D.assert(this._state != _DragState.ready);
if (!evt.synthesized
&& (evt is PointerDownEvent || evt is PointerMoveEvent)) {
var tracker = this._velocityTrackers[evt.pointer];
D.assert(tracker != null);
tracker.addPosition(evt.timeStamp, evt.position);
}
if (evt is PointerScrollEvent) {
Offset delta = evt.delta;
if (this.onUpdate != null) {

primaryVelocity: 0.0
));
return null;
}, debugReport: () => { return ""; }
}, debugReport: () => { return "Pointer scroll end"; }
}
if (!evt.synthesized
&& (evt is PointerDownEvent || evt is PointerMoveEvent)) {
var tracker = this._velocityTrackers[evt.pointer];
D.assert(tracker != null);
tracker.addPosition(evt.timeStamp, evt.position);
}
if (evt is PointerMoveEvent) {

2
Runtime/ui/txt/paragraph.cs


}
public List<TextBox> getRectsForRange(int start, int end) {
var lineBoxes = new SplayTree<int, List<TextBox>>();
var lineBoxes = new SortedDictionary<int, List<TextBox>>();
foreach (var run in this._codeUnitRuns) {
if (run.codeUnits.start >= end) {
break;

12
Runtime/widgets/sliver.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.widgets {
public abstract class SliverChildDelegate {

}
Dictionary<int, Widget> _childWidgets = new Dictionary<int, Widget>();
SplayTree<int, Element> _childElements = new SplayTree<int, Element>();
SortedDictionary<int, Element> _childElements = new SortedDictionary<int, Element>();
RenderBox _currentBeforeChild;
protected override void performRebuild() {

int lastIndex = 0;
if (!this._childElements.isEmpty()) {
firstIndex = this._childElements.First().Key;
lastIndex = this._childElements.Last().Key;
firstIndex = this._childElements.Keys.First();
lastIndex = this._childElements.Keys.Last();
if (this._didUnderflow) {
lastIndex += 1;
}

public void didFinishLayout() {
D.assert(this.debugAssertChildListLocked());
int firstIndex = this._childElements.FirstOrDefault().Key;
int lastIndex = this._childElements.LastOrDefault().Key;
int firstIndex = this._childElements.Keys.FirstOrDefault();
int lastIndex = this._childElements.Keys.LastOrDefault();
this.widget.del.didFinishLayout(firstIndex, lastIndex);
}

81
Runtime/editor/scroll_input.cs


using System;
using UnityEngine;
namespace Unity.UIWidgets.editor {
public class ScrollInput {
readonly int _bufferSize = 10;
readonly float _scrollScale = 10;
float _scrollDeltaX;
float _scrollDeltaY;
int _bufferIndex;
float _curDeltaX;
float _curDeltaY;
float _pointerX;
float _pointerY;
int _buttonId;
public ScrollInput(int bufferSize = 10, float scrollScale = 10) {
this._bufferIndex = bufferSize;
this._bufferSize = bufferSize;
this._scrollDeltaX = 0;
this._scrollDeltaY = 0;
this._curDeltaX = 0;
this._curDeltaY = 0;
this._scrollScale = scrollScale;
}
public void onScroll(float deltaX, float deltaY, float pointerX, float pointerY, int buttonId) {
this._scrollDeltaX += deltaX * this._scrollScale;
this._scrollDeltaY += deltaY * this._scrollScale;
this._bufferIndex = this._bufferSize;
this._curDeltaX = this._scrollDeltaX / this._bufferIndex;
this._curDeltaY = this._scrollDeltaY / this._bufferIndex;
this._pointerX = pointerX;
this._pointerY = pointerY;
this._buttonId = buttonId;
}
public int getDeviceId() {
return this._buttonId;
}
public float getPointerPosX() {
return this._pointerX;
}
public float getPointerPosY() {
return this._pointerY;
}
public Vector2 getScrollDelta() {
if (this._scrollDeltaX == 0 && this._scrollDeltaY == 0) {
return Vector2.zero;
}
var deltaScroll = new Vector2();
if (this._bufferIndex == 0) {
deltaScroll.x = this._scrollDeltaX;
deltaScroll.y = this._scrollDeltaY;
this._scrollDeltaX = 0;
this._scrollDeltaY = 0;
}
else {
deltaScroll.x = this._curDeltaX;
deltaScroll.y = this._curDeltaY;
this._scrollDeltaX = this._curDeltaX > 0
? Math.Max(0, this._scrollDeltaX - this._curDeltaX)
: Math.Min(0, this._scrollDeltaX - this._curDeltaX);
this._scrollDeltaY = this._curDeltaY > 0
? Math.Max(0, this._scrollDeltaY - this._curDeltaY)
: Math.Min(0, this._scrollDeltaY - this._curDeltaY);
this._bufferIndex--;
}
return deltaScroll;
}
}
}

11
Runtime/editor/scroll_input.cs.meta


fileFormatVersion: 2
guid: 492cc1893411b4b5085b8db85e96ca5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存