Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

fix conflict between drag & scroll #373

Merged
merged 3 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Runtime/editor/editor_window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,33 @@ namespace Unity.UIWidgets.editor {
#if UNITY_EDITOR
public abstract class UIWidgetsEditorWindow : EditorWindow, WindowHost {
WindowAdapter _windowAdapter;


static readonly List<UIWidgetsEditorWindow> _activeEditorWindows = new List<UIWidgetsEditorWindow>();

[InitializeOnLoadMethod]
static void _OnBaseEditorWindowLoaded()
{
EditorApplication.quitting += () =>
{
foreach (var editorWindow in _activeEditorWindows) {
editorWindow.OnDisable();
}

_activeEditorWindows.Clear();
};
}

public UIWidgetsEditorWindow() {
this.wantsMouseMove = true;
this.wantsMouseEnterLeaveWindow = true;

_activeEditorWindows.Add(this);
}

void OnDestroy() {
if (_activeEditorWindows.Contains(this)) {
_activeEditorWindows.Remove(this);
}
}

protected virtual void OnEnable() {
Expand Down Expand Up @@ -404,7 +427,7 @@ void _doOnGUI(Event evt) {
-evt.delta.y * this._devicePixelRatio,
evt.mousePosition.x * this._devicePixelRatio,
evt.mousePosition.y * this._devicePixelRatio,
InputUtils.getMouseButtonKey(evt.button)
InputUtils.getScrollButtonKey()
);
}
else if (evt.type == EventType.DragUpdated) {
Expand Down
3 changes: 3 additions & 0 deletions Runtime/gestures/binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ evt is PointerDragFromEditorReleaseEvent

void _handlePointerScrollEvent(PointerEvent evt) {
this.pointerRouter.clearScrollRoute(evt.pointer);
if (!this.pointerRouter.acceptScroll()) {
return;
}

HitTestResult result = new HitTestResult();
this.hitTest(result, evt.position);
Expand Down
4 changes: 4 additions & 0 deletions Runtime/gestures/pointer_router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public void removeRoute(int pointer, PointerRoute route) {
this._routeMap.Remove(pointer);
}
}

public bool acceptScroll() {
return this._routeMap.Count == 0;
}

public void clearScrollRoute(int pointer) {
if (this._routeMap.ContainsKey(pointer)) {
Expand Down
3 changes: 3 additions & 0 deletions Runtime/service/text_input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ public TextEditingValue compose(string composeText) {
D.assert(!string.IsNullOrEmpty(composeText));
var composeStart = this.composing == TextRange.empty ? this.selection.start : this.composing.start;
var lastComposeEnd = this.composing == TextRange.empty ? this.selection.end : this.composing.end;

composeStart = Mathf.Clamp(composeStart, 0, this.text.Length);
lastComposeEnd = Mathf.Clamp(lastComposeEnd, 0, this.text.Length);
var newText = this.text.Substring(0, composeStart) + composeText + this.text.Substring(lastComposeEnd);
var componseEnd = composeStart + composeText.Length;
return new TextEditingValue(
Expand Down